use ::libc;
extern "C" {
    pub type event_base;
    pub type evbuffer;
    pub type bufferevent_ops;
    pub type args;
    pub type tmuxpeer;
    pub type hyperlinks;
    pub type screen_write_cline;
    pub type screen_sel;
    pub type screen_titles;
    pub type environ;
    pub type cmds;
    pub type format_tree;
    pub type input_ctx;
    pub type tty_key;
    pub type tty_code;
    pub type format_job_tree;
    pub type control_state;
    pub type cmdq_list;
    pub type cmdq_item;
    fn __ctype_b_loc() -> *mut *const u16;
    fn fnmatch(
        __pattern: *const i8,
        __name: *const i8,
        __flags: i32,
    ) -> i32;
    fn free(_: *mut libc::c_void);
    fn strcmp(_: *const i8, _: *const i8) -> i32;
    fn strncmp(_: *const i8, _: *const i8, _: u64) -> i32;
    fn strchr(_: *const i8, _: i32) -> *mut i8;
    fn strstr(_: *const i8, _: *const i8) -> *mut i8;
    fn strlen(_: *const i8) -> u64;
    fn strsep(__stringp: *mut *mut i8, __delim: *const i8)
        -> *mut i8;
    fn strcasecmp(_: *const i8, _: *const i8) -> i32;
    fn sscanf(_: *const i8, _: *const i8, _: ...) -> i32;
    fn strtonum(
        _: *const i8,
        _: i64,
        _: i64,
        _: *mut *const i8,
    ) -> i64;
    fn xcalloc(_: size_t, _: size_t) -> *mut libc::c_void;
    fn xstrdup(_: *const i8) -> *mut i8;
    fn xasprintf(_: *mut *mut i8, _: *const i8, _: ...) -> i32;
    fn xvasprintf(
        _: *mut *mut i8,
        _: *const i8,
        _: ::core::ffi::VaList,
    ) -> i32;
    static mut global_options: *mut options;
    static mut global_s_options: *mut options;
    static mut global_w_options: *mut options;
    fn checkshell(_: *const i8) -> i32;
    fn format_expand(_: *mut format_tree, _: *const i8) -> *mut i8;
    fn cmd_list_free(_: *mut cmd_list);
    static options_other_names: [options_name_map; 0];
    fn cmd_parse_from_string(
        _: *const i8,
        _: *mut cmd_parse_input,
    ) -> *mut cmd_parse_result;
    fn key_string_lookup_key(_: key_code, _: i32) -> *const i8;
    fn cmd_list_print(_: *mut cmd_list, _: i32) -> *mut i8;
    static options_table: [options_table_entry; 0];
    fn args_get(_: *mut args, _: u_char) -> *const i8;
    fn args_has(_: *mut args, _: u_char) -> i32;
    fn key_string_lookup_string(_: *const i8) -> key_code;
    static mut clients: clients;
    fn alerts_reset_all();
    fn tty_keys_build(_: *mut tty);
    fn server_client_set_key_table(_: *mut client, _: *const i8);
    fn status_timer_start_all();
    fn colour_palette_from_option(_: *mut colour_palette, _: *mut options);
    fn window_pane_tree_RB_MINMAX(_: *mut window_pane_tree, _: i32) -> *mut window_pane;
    static mut all_window_panes: window_pane_tree;
    fn window_pane_tree_RB_NEXT(_: *mut window_pane) -> *mut window_pane;
    fn windows_RB_MINMAX(_: *mut windows, _: i32) -> *mut window;
    static mut windows: windows;
    fn windows_RB_NEXT(_: *mut window) -> *mut window;
    fn input_set_buffer_size(_: size_t);
    fn status_update_cache(_: *mut session);
    fn recalculate_sizes();
    fn server_redraw_client(_: *mut client);
    static grid_default_cell: grid_cell;
    fn colour_tostring(_: i32) -> *const i8;
    fn colour_fromstring(s: *const i8) -> i32;
    fn layout_fix_panes(_: *mut window, _: *mut window_pane);
    fn window_set_fill_character(_: *mut window);
    fn window_pane_default_cursor(_: *mut window_pane);
    fn sessions_RB_MINMAX(_: *mut sessions, _: i32) -> *mut session;
    static mut sessions: sessions;
    fn sessions_RB_NEXT(_: *mut session) -> *mut session;
    fn style_parse(_: *mut style, _: *const grid_cell, _: *const i8) -> i32;
    fn style_set(_: *mut style, _: *const grid_cell);
    fn log_debug(_: *const i8, _: ...);
    fn style_set_scrollbar_style_from_option(_: *mut style, _: *mut options);
    fn fatalx(_: *const i8, _: ...) -> !;
}
pub type __builtin_va_list = [__va_list_tag; 1];
#[derive(Copy, Clone)]
#[repr(C)]
pub struct __va_list_tag {
    pub gp_offset: u32,
    pub fp_offset: u32,
    pub overflow_arg_area: *mut libc::c_void,
    pub reg_save_area: *mut libc::c_void,
}
pub type __u_char = u8;
pub type __u_short = u16;
pub type __u_int = u32;
pub type __uint8_t = u8;
pub type __uint64_t = u64;
pub type __pid_t = i32;
pub type __time_t = i64;
pub type __suseconds_t = i64;
pub type u_char = __u_char;
pub type u_short = __u_short;
pub type u_int = __u_int;
pub type pid_t = __pid_t;
pub type time_t = __time_t;
pub type size_t = u64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct timeval {
    pub tv_sec: __time_t,
    pub tv_usec: __suseconds_t,
}
pub type C2RustUnnamed = u32;
pub const _ISalnum: C2RustUnnamed = 8;
pub const _ISpunct: C2RustUnnamed = 4;
pub const _IScntrl: C2RustUnnamed = 2;
pub const _ISblank: C2RustUnnamed = 1;
pub const _ISgraph: C2RustUnnamed = 32768;
pub const _ISprint: C2RustUnnamed = 16384;
pub const _ISspace: C2RustUnnamed = 8192;
pub const _ISxdigit: C2RustUnnamed = 4096;
pub const _ISdigit: C2RustUnnamed = 2048;
pub const _ISalpha: C2RustUnnamed = 1024;
pub const _ISlower: C2RustUnnamed = 512;
pub const _ISupper: C2RustUnnamed = 256;
pub type va_list = __builtin_va_list;
pub type cc_t = u8;
pub type speed_t = u32;
pub type tcflag_t = u32;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct termios {
    pub c_iflag: tcflag_t,
    pub c_oflag: tcflag_t,
    pub c_cflag: tcflag_t,
    pub c_lflag: tcflag_t,
    pub c_line: cc_t,
    pub c_cc: [cc_t; 32],
    pub c_ispeed: speed_t,
    pub c_ospeed: speed_t,
}
pub type uint8_t = __uint8_t;
pub type uint64_t = __uint64_t;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event {
    pub ev_evcallback: event_callback,
    pub ev_timeout_pos: C2RustUnnamed_5,
    pub ev_fd: i32,
    pub ev_base: *mut event_base,
    pub ev_: C2RustUnnamed_0,
    pub ev_events: i16,
    pub ev_res: i16,
    pub ev_timeout: timeval,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_0 {
    pub ev_io: C2RustUnnamed_3,
    pub ev_signal: C2RustUnnamed_1,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_1 {
    pub ev_signal_next: C2RustUnnamed_2,
    pub ev_ncalls: i16,
    pub ev_pncalls: *mut i16,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_2 {
    pub le_next: *mut event,
    pub le_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_3 {
    pub ev_io_next: C2RustUnnamed_4,
    pub ev_timeout: timeval,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_4 {
    pub le_next: *mut event,
    pub le_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_5 {
    pub ev_next_with_common_timeout: C2RustUnnamed_6,
    pub min_heap_idx: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_6 {
    pub tqe_next: *mut event,
    pub tqe_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event_callback {
    pub evcb_active_next: C2RustUnnamed_8,
    pub evcb_flags: i16,
    pub evcb_pri: uint8_t,
    pub evcb_closure: uint8_t,
    pub evcb_cb_union: C2RustUnnamed_7,
    pub evcb_arg: *mut libc::c_void,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_7 {
    pub evcb_callback:
        Option<unsafe extern "C" fn(i32, i16, *mut libc::c_void) -> ()>,
    pub evcb_selfcb: Option<unsafe extern "C" fn(*mut event_callback, *mut libc::c_void) -> ()>,
    pub evcb_evfinalize: Option<unsafe extern "C" fn(*mut event, *mut libc::c_void) -> ()>,
    pub evcb_cbfinalize: Option<unsafe extern "C" fn(*mut event_callback, *mut libc::c_void) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_8 {
    pub tqe_next: *mut event_callback,
    pub tqe_prev: *mut *mut event_callback,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct bufferevent {
    pub ev_base: *mut event_base,
    pub be_ops: *const bufferevent_ops,
    pub ev_read: event,
    pub ev_write: event,
    pub input: *mut evbuffer,
    pub output: *mut evbuffer,
    pub wm_read: event_watermark,
    pub wm_write: event_watermark,
    pub readcb: bufferevent_data_cb,
    pub writecb: bufferevent_data_cb,
    pub errorcb: bufferevent_event_cb,
    pub cbarg: *mut libc::c_void,
    pub timeout_read: timeval,
    pub timeout_write: timeval,
    pub enabled: i16,
}
pub type bufferevent_event_cb =
    Option<unsafe extern "C" fn(*mut bufferevent, i16, *mut libc::c_void) -> ()>;
pub type bufferevent_data_cb =
    Option<unsafe extern "C" fn(*mut bufferevent, *mut libc::c_void) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event_watermark {
    pub low: size_t,
    pub high: size_t,
}
pub type bitstr_t = u8;
pub type msgtype = u32;
pub const MSG_READ_CANCEL: msgtype = 307;
pub const MSG_WRITE_CLOSE: msgtype = 306;
pub const MSG_WRITE_READY: msgtype = 305;
pub const MSG_WRITE: msgtype = 304;
pub const MSG_WRITE_OPEN: msgtype = 303;
pub const MSG_READ_DONE: msgtype = 302;
pub const MSG_READ: msgtype = 301;
pub const MSG_READ_OPEN: msgtype = 300;
pub const MSG_FLAGS: msgtype = 218;
pub const MSG_EXEC: msgtype = 217;
pub const MSG_WAKEUP: msgtype = 216;
pub const MSG_UNLOCK: msgtype = 215;
pub const MSG_SUSPEND: msgtype = 214;
pub const MSG_OLDSTDOUT: msgtype = 213;
pub const MSG_OLDSTDIN: msgtype = 212;
pub const MSG_OLDSTDERR: msgtype = 211;
pub const MSG_SHUTDOWN: msgtype = 210;
pub const MSG_SHELL: msgtype = 209;
pub const MSG_RESIZE: msgtype = 208;
pub const MSG_READY: msgtype = 207;
pub const MSG_LOCK: msgtype = 206;
pub const MSG_EXITING: msgtype = 205;
pub const MSG_EXITED: msgtype = 204;
pub const MSG_EXIT: msgtype = 203;
pub const MSG_DETACHKILL: msgtype = 202;
pub const MSG_DETACH: msgtype = 201;
pub const MSG_COMMAND: msgtype = 200;
pub const MSG_IDENTIFY_TERMINFO: msgtype = 112;
pub const MSG_IDENTIFY_LONGFLAGS: msgtype = 111;
pub const MSG_IDENTIFY_STDOUT: msgtype = 110;
pub const MSG_IDENTIFY_FEATURES: msgtype = 109;
pub const MSG_IDENTIFY_CWD: msgtype = 108;
pub const MSG_IDENTIFY_CLIENTPID: msgtype = 107;
pub const MSG_IDENTIFY_DONE: msgtype = 106;
pub const MSG_IDENTIFY_ENVIRON: msgtype = 105;
pub const MSG_IDENTIFY_STDIN: msgtype = 104;
pub const MSG_IDENTIFY_OLDCWD: msgtype = 103;
pub const MSG_IDENTIFY_TTYNAME: msgtype = 102;
pub const MSG_IDENTIFY_TERM: msgtype = 101;
pub const MSG_IDENTIFY_FLAGS: msgtype = 100;
pub const MSG_VERSION: msgtype = 12;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client {
    pub name: *const i8,
    pub peer: *mut tmuxpeer,
    pub queue: *mut cmdq_list,
    pub windows: client_windows,
    pub control_state: *mut control_state,
    pub pause_age: u_int,
    pub pid: pid_t,
    pub fd: i32,
    pub out_fd: i32,
    pub event: event,
    pub retval: i32,
    pub creation_time: timeval,
    pub activity_time: timeval,
    pub last_activity_time: timeval,
    pub environ: *mut environ,
    pub jobs: *mut format_job_tree,
    pub title: *mut i8,
    pub path: *mut i8,
    pub cwd: *const i8,
    pub term_name: *mut i8,
    pub term_features: i32,
    pub term_type: *mut i8,
    pub term_caps: *mut *mut i8,
    pub term_ncaps: u_int,
    pub ttyname: *mut i8,
    pub tty: tty,
    pub written: size_t,
    pub discarded: size_t,
    pub redraw: size_t,
    pub repeat_timer: event,
    pub click_timer: event,
    pub click_button: u_int,
    pub click_event: mouse_event,
    pub status: status_line,
    pub flags: uint64_t,
    pub exit_type: C2RustUnnamed_33,
    pub exit_msgtype: msgtype,
    pub exit_session: *mut i8,
    pub exit_message: *mut i8,
    pub keytable: *mut key_table,
    pub last_key: key_code,
    pub redraw_panes: uint64_t,
    pub redraw_scrollbars: uint64_t,
    pub message_ignore_keys: i32,
    pub message_ignore_styles: i32,
    pub message_string: *mut i8,
    pub message_timer: event,
    pub prompt_string: *mut i8,
    pub prompt_buffer: *mut utf8_data,
    pub prompt_last: *mut i8,
    pub prompt_index: size_t,
    pub prompt_inputcb: prompt_input_cb,
    pub prompt_freecb: prompt_free_cb,
    pub prompt_data: *mut libc::c_void,
    pub prompt_hindex: [u_int; 4],
    pub prompt_mode: C2RustUnnamed_30,
    pub prompt_saved: *mut utf8_data,
    pub prompt_flags: i32,
    pub prompt_type: prompt_type,
    pub prompt_cursor: i32,
    pub session: *mut session,
    pub last_session: *mut session,
    pub references: i32,
    pub pan_window: *mut libc::c_void,
    pub pan_ox: u_int,
    pub pan_oy: u_int,
    pub overlay_check: overlay_check_cb,
    pub overlay_mode: overlay_mode_cb,
    pub overlay_draw: overlay_draw_cb,
    pub overlay_key: overlay_key_cb,
    pub overlay_free: overlay_free_cb,
    pub overlay_resize: overlay_resize_cb,
    pub overlay_data: *mut libc::c_void,
    pub overlay_timer: event,
    pub files: client_files,
    pub clipboard_panes: *mut u_int,
    pub clipboard_npanes: u_int,
    pub entry: C2RustUnnamed_9,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_9 {
    pub tqe_next: *mut client,
    pub tqe_prev: *mut *mut client,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_files {
    pub rbh_root: *mut client_file,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_file {
    pub c: *mut client,
    pub peer: *mut tmuxpeer,
    pub tree: *mut client_files,
    pub references: i32,
    pub stream: i32,
    pub path: *mut i8,
    pub buffer: *mut evbuffer,
    pub event: *mut bufferevent,
    pub fd: i32,
    pub error: i32,
    pub closed: i32,
    pub cb: client_file_cb,
    pub data: *mut libc::c_void,
    pub entry: C2RustUnnamed_10,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_10 {
    pub rbe_left: *mut client_file,
    pub rbe_right: *mut client_file,
    pub rbe_parent: *mut client_file,
    pub rbe_color: i32,
}
pub type client_file_cb = Option<
    unsafe extern "C" fn(
        *mut client,
        *const i8,
        i32,
        i32,
        *mut evbuffer,
        *mut libc::c_void,
    ) -> (),
>;
pub type overlay_resize_cb = Option<unsafe extern "C" fn(*mut client, *mut libc::c_void) -> ()>;
pub type overlay_free_cb = Option<unsafe extern "C" fn(*mut client, *mut libc::c_void) -> ()>;
pub type overlay_key_cb =
    Option<unsafe extern "C" fn(*mut client, *mut libc::c_void, *mut key_event) -> i32>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_event {
    pub key: key_code,
    pub m: mouse_event,
    pub buf: *mut i8,
    pub len: size_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct mouse_event {
    pub valid: i32,
    pub ignore: i32,
    pub key: key_code,
    pub statusat: i32,
    pub statuslines: u_int,
    pub x: u_int,
    pub y: u_int,
    pub b: u_int,
    pub lx: u_int,
    pub ly: u_int,
    pub lb: u_int,
    pub ox: u_int,
    pub oy: u_int,
    pub s: i32,
    pub w: i32,
    pub wp: i32,
    pub sgr_type: u_int,
    pub sgr_b: u_int,
}
pub type key_code = u64;
pub type overlay_draw_cb =
    Option<unsafe extern "C" fn(*mut client, *mut libc::c_void, *mut screen_redraw_ctx) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen_redraw_ctx {
    pub c: *mut client,
    pub statuslines: u_int,
    pub statustop: i32,
    pub pane_status: i32,
    pub pane_lines: pane_lines,
    pub pane_scrollbars: i32,
    pub pane_scrollbars_pos: i32,
    pub no_pane_gc: grid_cell,
    pub no_pane_gc_set: i32,
    pub sx: u_int,
    pub sy: u_int,
    pub ox: u_int,
    pub oy: u_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid_cell {
    pub data: utf8_data,
    pub attr: u_short,
    pub flags: u_char,
    pub fg: i32,
    pub bg: i32,
    pub us: i32,
    pub link: u_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct utf8_data {
    pub data: [u_char; 21],
    pub have: u_char,
    pub size: u_char,
    pub width: u_char,
}
pub type pane_lines = u32;
pub const PANE_LINES_NUMBER: pane_lines = 4;
pub const PANE_LINES_SIMPLE: pane_lines = 3;
pub const PANE_LINES_HEAVY: pane_lines = 2;
pub const PANE_LINES_DOUBLE: pane_lines = 1;
pub const PANE_LINES_SINGLE: pane_lines = 0;
pub type overlay_mode_cb = Option<
    unsafe extern "C" fn(*mut client, *mut libc::c_void, *mut u_int, *mut u_int) -> *mut screen,
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen {
    pub title: *mut i8,
    pub path: *mut i8,
    pub titles: *mut screen_titles,
    pub grid: *mut grid,
    pub cx: u_int,
    pub cy: u_int,
    pub cstyle: screen_cursor_style,
    pub default_cstyle: screen_cursor_style,
    pub ccolour: i32,
    pub default_ccolour: i32,
    pub rupper: u_int,
    pub rlower: u_int,
    pub mode: i32,
    pub default_mode: i32,
    pub saved_cx: u_int,
    pub saved_cy: u_int,
    pub saved_grid: *mut grid,
    pub saved_cell: grid_cell,
    pub saved_flags: i32,
    pub tabs: *mut bitstr_t,
    pub sel: *mut screen_sel,
    pub write_list: *mut screen_write_cline,
    pub hyperlinks: *mut hyperlinks,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid {
    pub flags: i32,
    pub sx: u_int,
    pub sy: u_int,
    pub hscrolled: u_int,
    pub hsize: u_int,
    pub hlimit: u_int,
    pub linedata: *mut grid_line,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid_line {
    pub celldata: *mut grid_cell_entry,
    pub cellused: u_int,
    pub cellsize: u_int,
    pub extddata: *mut grid_extd_entry,
    pub extdsize: u_int,
    pub flags: i32,
    pub time: time_t,
}
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct grid_extd_entry {
    pub data: utf8_char,
    pub attr: u_short,
    pub flags: u_char,
    pub fg: i32,
    pub bg: i32,
    pub us: i32,
    pub link: u_int,
}
pub type utf8_char = u_int;
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct grid_cell_entry {
    pub c2rust_unnamed: C2RustUnnamed_11,
    pub flags: u_char,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_11 {
    pub offset: u_int,
    pub data: C2RustUnnamed_12,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_12 {
    pub attr: u_char,
    pub fg: u_char,
    pub bg: u_char,
    pub data: u_char,
}
pub type screen_cursor_style = u32;
pub const SCREEN_CURSOR_BAR: screen_cursor_style = 3;
pub const SCREEN_CURSOR_UNDERLINE: screen_cursor_style = 2;
pub const SCREEN_CURSOR_BLOCK: screen_cursor_style = 1;
pub const SCREEN_CURSOR_DEFAULT: screen_cursor_style = 0;
pub type overlay_check_cb = Option<
    unsafe extern "C" fn(
        *mut client,
        *mut libc::c_void,
        u_int,
        u_int,
        u_int,
        *mut overlay_ranges,
    ) -> (),
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct overlay_ranges {
    pub px: [u_int; 3],
    pub nx: [u_int; 3],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct session {
    pub id: u_int,
    pub name: *mut i8,
    pub cwd: *const i8,
    pub creation_time: timeval,
    pub last_attached_time: timeval,
    pub activity_time: timeval,
    pub last_activity_time: timeval,
    pub lock_timer: event,
    pub curw: *mut winlink,
    pub lastw: winlink_stack,
    pub windows: winlinks,
    pub statusat: i32,
    pub statuslines: u_int,
    pub options: *mut options,
    pub flags: i32,
    pub attached: u_int,
    pub tio: *mut termios,
    pub environ: *mut environ,
    pub references: i32,
    pub gentry: C2RustUnnamed_14,
    pub entry: C2RustUnnamed_13,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_13 {
    pub rbe_left: *mut session,
    pub rbe_right: *mut session,
    pub rbe_parent: *mut session,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_14 {
    pub tqe_next: *mut session,
    pub tqe_prev: *mut *mut session,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct options {
    pub tree: options_tree,
    pub parent: *mut options,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct options_tree {
    pub rbh_root: *mut options_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct options_entry {
    pub owner: *mut options,
    pub name: *const i8,
    pub tableentry: *const options_table_entry,
    pub value: options_value,
    pub cached: i32,
    pub style: style,
    pub entry: C2RustUnnamed_15,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_15 {
    pub rbe_left: *mut options_entry,
    pub rbe_right: *mut options_entry,
    pub rbe_parent: *mut options_entry,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style {
    pub gc: grid_cell,
    pub ignore: i32,
    pub fill: i32,
    pub align: style_align,
    pub list: style_list,
    pub range_type: style_range_type,
    pub range_argument: u_int,
    pub range_string: [i8; 16],
    pub width: i32,
    pub pad: i32,
    pub default_type: style_default_type,
}
pub type style_default_type = u32;
pub const STYLE_DEFAULT_POP: style_default_type = 2;
pub const STYLE_DEFAULT_PUSH: style_default_type = 1;
pub const STYLE_DEFAULT_BASE: style_default_type = 0;
pub type style_range_type = u32;
pub const STYLE_RANGE_USER: style_range_type = 6;
pub const STYLE_RANGE_SESSION: style_range_type = 5;
pub const STYLE_RANGE_WINDOW: style_range_type = 4;
pub const STYLE_RANGE_PANE: style_range_type = 3;
pub const STYLE_RANGE_RIGHT: style_range_type = 2;
pub const STYLE_RANGE_LEFT: style_range_type = 1;
pub const STYLE_RANGE_NONE: style_range_type = 0;
pub type style_list = u32;
pub const STYLE_LIST_RIGHT_MARKER: style_list = 4;
pub const STYLE_LIST_LEFT_MARKER: style_list = 3;
pub const STYLE_LIST_FOCUS: style_list = 2;
pub const STYLE_LIST_ON: style_list = 1;
pub const STYLE_LIST_OFF: style_list = 0;
pub type style_align = u32;
pub const STYLE_ALIGN_ABSOLUTE_CENTRE: style_align = 4;
pub const STYLE_ALIGN_RIGHT: style_align = 3;
pub const STYLE_ALIGN_CENTRE: style_align = 2;
pub const STYLE_ALIGN_LEFT: style_align = 1;
pub const STYLE_ALIGN_DEFAULT: style_align = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub union options_value {
    pub string: *mut i8,
    pub number: i64,
    pub style: style,
    pub array: options_array,
    pub cmdlist: *mut cmd_list,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_list {
    pub references: i32,
    pub group: u_int,
    pub list: *mut cmds,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct options_array {
    pub rbh_root: *mut options_array_item,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct options_array_item {
    pub index: u_int,
    pub value: options_value,
    pub entry: C2RustUnnamed_16,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_16 {
    pub rbe_left: *mut options_array_item,
    pub rbe_right: *mut options_array_item,
    pub rbe_parent: *mut options_array_item,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct options_table_entry {
    pub name: *const i8,
    pub alternative_name: *const i8,
    pub type_0: options_table_type,
    pub scope: i32,
    pub flags: i32,
    pub minimum: u_int,
    pub maximum: u_int,
    pub choices: *mut *const i8,
    pub default_str: *const i8,
    pub default_num: i64,
    pub default_arr: *mut *const i8,
    pub separator: *const i8,
    pub pattern: *const i8,
    pub text: *const i8,
    pub unit: *const i8,
}
pub type options_table_type = u32;
pub const OPTIONS_TABLE_COMMAND: options_table_type = 6;
pub const OPTIONS_TABLE_CHOICE: options_table_type = 5;
pub const OPTIONS_TABLE_FLAG: options_table_type = 4;
pub const OPTIONS_TABLE_COLOUR: options_table_type = 3;
pub const OPTIONS_TABLE_KEY: options_table_type = 2;
pub const OPTIONS_TABLE_NUMBER: options_table_type = 1;
pub const OPTIONS_TABLE_STRING: options_table_type = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlinks {
    pub rbh_root: *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlink {
    pub idx: i32,
    pub session: *mut session,
    pub window: *mut window,
    pub flags: i32,
    pub entry: C2RustUnnamed_19,
    pub wentry: C2RustUnnamed_18,
    pub sentry: C2RustUnnamed_17,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_17 {
    pub tqe_next: *mut winlink,
    pub tqe_prev: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_18 {
    pub tqe_next: *mut winlink,
    pub tqe_prev: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_19 {
    pub rbe_left: *mut winlink,
    pub rbe_right: *mut winlink,
    pub rbe_parent: *mut winlink,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window {
    pub id: u_int,
    pub latest: *mut libc::c_void,
    pub name: *mut i8,
    pub name_event: event,
    pub name_time: timeval,
    pub alerts_timer: event,
    pub offset_timer: event,
    pub activity_time: timeval,
    pub active: *mut window_pane,
    pub last_panes: window_panes,
    pub panes: window_panes,
    pub lastlayout: i32,
    pub layout_root: *mut layout_cell,
    pub saved_layout_root: *mut layout_cell,
    pub old_layout: *mut i8,
    pub sx: u_int,
    pub sy: u_int,
    pub manual_sx: u_int,
    pub manual_sy: u_int,
    pub xpixel: u_int,
    pub ypixel: u_int,
    pub new_sx: u_int,
    pub new_sy: u_int,
    pub new_xpixel: u_int,
    pub new_ypixel: u_int,
    pub fill_character: *mut utf8_data,
    pub flags: i32,
    pub alerts_queued: i32,
    pub alerts_entry: C2RustUnnamed_22,
    pub options: *mut options,
    pub references: u_int,
    pub winlinks: C2RustUnnamed_21,
    pub entry: C2RustUnnamed_20,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_20 {
    pub rbe_left: *mut window,
    pub rbe_right: *mut window,
    pub rbe_parent: *mut window,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_21 {
    pub tqh_first: *mut winlink,
    pub tqh_last: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_22 {
    pub tqe_next: *mut window,
    pub tqe_prev: *mut *mut window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct layout_cell {
    pub type_0: layout_type,
    pub parent: *mut layout_cell,
    pub sx: u_int,
    pub sy: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub wp: *mut window_pane,
    pub cells: layout_cells,
    pub entry: C2RustUnnamed_23,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_23 {
    pub tqe_next: *mut layout_cell,
    pub tqe_prev: *mut *mut layout_cell,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct layout_cells {
    pub tqh_first: *mut layout_cell,
    pub tqh_last: *mut *mut layout_cell,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane {
    pub id: u_int,
    pub active_point: u_int,
    pub window: *mut window,
    pub options: *mut options,
    pub layout_cell: *mut layout_cell,
    pub saved_layout_cell: *mut layout_cell,
    pub sx: u_int,
    pub sy: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub flags: i32,
    pub sb_slider_y: u_int,
    pub sb_slider_h: u_int,
    pub argc: i32,
    pub argv: *mut *mut i8,
    pub shell: *mut i8,
    pub cwd: *mut i8,
    pub pid: pid_t,
    pub tty: [i8; 32],
    pub status: i32,
    pub dead_time: timeval,
    pub fd: i32,
    pub event: *mut bufferevent,
    pub offset: window_pane_offset,
    pub base_offset: size_t,
    pub resize_queue: window_pane_resizes,
    pub resize_timer: event,
    pub ictx: *mut input_ctx,
    pub cached_gc: grid_cell,
    pub cached_active_gc: grid_cell,
    pub palette: colour_palette,
    pub pipe_fd: i32,
    pub pipe_event: *mut bufferevent,
    pub pipe_offset: window_pane_offset,
    pub screen: *mut screen,
    pub base: screen,
    pub status_screen: screen,
    pub status_size: size_t,
    pub modes: C2RustUnnamed_27,
    pub searchstr: *mut i8,
    pub searchregex: i32,
    pub border_gc_set: i32,
    pub border_gc: grid_cell,
    pub control_bg: i32,
    pub control_fg: i32,
    pub scrollbar_style: style,
    pub entry: C2RustUnnamed_26,
    pub sentry: C2RustUnnamed_25,
    pub tree_entry: C2RustUnnamed_24,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_24 {
    pub rbe_left: *mut window_pane,
    pub rbe_right: *mut window_pane,
    pub rbe_parent: *mut window_pane,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_25 {
    pub tqe_next: *mut window_pane,
    pub tqe_prev: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_26 {
    pub tqe_next: *mut window_pane,
    pub tqe_prev: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_27 {
    pub tqh_first: *mut window_mode_entry,
    pub tqh_last: *mut *mut window_mode_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_mode_entry {
    pub wp: *mut window_pane,
    pub swp: *mut window_pane,
    pub mode: *const window_mode,
    pub data: *mut libc::c_void,
    pub screen: *mut screen,
    pub prefix: u_int,
    pub entry: C2RustUnnamed_28,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_28 {
    pub tqe_next: *mut window_mode_entry,
    pub tqe_prev: *mut *mut window_mode_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_mode {
    pub name: *const i8,
    pub default_format: *const i8,
    pub init: Option<
        unsafe extern "C" fn(*mut window_mode_entry, *mut cmd_find_state, *mut args) -> *mut screen,
    >,
    pub free: Option<unsafe extern "C" fn(*mut window_mode_entry) -> ()>,
    pub resize: Option<unsafe extern "C" fn(*mut window_mode_entry, u_int, u_int) -> ()>,
    pub update: Option<unsafe extern "C" fn(*mut window_mode_entry) -> ()>,
    pub key: Option<
        unsafe extern "C" fn(
            *mut window_mode_entry,
            *mut client,
            *mut session,
            *mut winlink,
            key_code,
            *mut mouse_event,
        ) -> (),
    >,
    pub key_table: Option<unsafe extern "C" fn(*mut window_mode_entry) -> *const i8>,
    pub command: Option<
        unsafe extern "C" fn(
            *mut window_mode_entry,
            *mut client,
            *mut session,
            *mut winlink,
            *mut args,
            *mut mouse_event,
        ) -> (),
    >,
    pub formats: Option<unsafe extern "C" fn(*mut window_mode_entry, *mut format_tree) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_find_state {
    pub flags: i32,
    pub current: *mut cmd_find_state,
    pub s: *mut session,
    pub wl: *mut winlink,
    pub w: *mut window,
    pub wp: *mut window_pane,
    pub idx: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_offset {
    pub used: size_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct colour_palette {
    pub fg: i32,
    pub bg: i32,
    pub palette: *mut i32,
    pub default_palette: *mut i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_resizes {
    pub tqh_first: *mut window_pane_resize,
    pub tqh_last: *mut *mut window_pane_resize,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_resize {
    pub sx: u_int,
    pub sy: u_int,
    pub osx: u_int,
    pub osy: u_int,
    pub entry: C2RustUnnamed_29,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_29 {
    pub tqe_next: *mut window_pane_resize,
    pub tqe_prev: *mut *mut window_pane_resize,
}
pub type layout_type = u32;
pub const LAYOUT_WINDOWPANE: layout_type = 2;
pub const LAYOUT_TOPBOTTOM: layout_type = 1;
pub const LAYOUT_LEFTRIGHT: layout_type = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_panes {
    pub tqh_first: *mut window_pane,
    pub tqh_last: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlink_stack {
    pub tqh_first: *mut winlink,
    pub tqh_last: *mut *mut winlink,
}
pub type prompt_type = u32;
pub const PROMPT_TYPE_INVALID: prompt_type = 255;
pub const PROMPT_TYPE_WINDOW_TARGET: prompt_type = 3;
pub const PROMPT_TYPE_TARGET: prompt_type = 2;
pub const PROMPT_TYPE_SEARCH: prompt_type = 1;
pub const PROMPT_TYPE_COMMAND: prompt_type = 0;
pub type C2RustUnnamed_30 = u32;
pub const PROMPT_COMMAND: C2RustUnnamed_30 = 1;
pub const PROMPT_ENTRY: C2RustUnnamed_30 = 0;
pub type prompt_free_cb = Option<unsafe extern "C" fn(*mut libc::c_void) -> ()>;
pub type prompt_input_cb = Option<
    unsafe extern "C" fn(
        *mut client,
        *mut libc::c_void,
        *const i8,
        i32,
    ) -> i32,
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_table {
    pub name: *const i8,
    pub activity_time: timeval,
    pub key_bindings: key_bindings,
    pub default_key_bindings: key_bindings,
    pub references: u_int,
    pub entry: C2RustUnnamed_31,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_31 {
    pub rbe_left: *mut key_table,
    pub rbe_right: *mut key_table,
    pub rbe_parent: *mut key_table,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_bindings {
    pub rbh_root: *mut key_binding,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_binding {
    pub key: key_code,
    pub cmdlist: *mut cmd_list,
    pub note: *const i8,
    pub flags: i32,
    pub entry: C2RustUnnamed_32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_32 {
    pub rbe_left: *mut key_binding,
    pub rbe_right: *mut key_binding,
    pub rbe_parent: *mut key_binding,
    pub rbe_color: i32,
}
pub type C2RustUnnamed_33 = u32;
pub const CLIENT_EXIT_DETACH: C2RustUnnamed_33 = 2;
pub const CLIENT_EXIT_SHUTDOWN: C2RustUnnamed_33 = 1;
pub const CLIENT_EXIT_RETURN: C2RustUnnamed_33 = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct status_line {
    pub timer: event,
    pub screen: screen,
    pub active: *mut screen,
    pub references: i32,
    pub style: grid_cell,
    pub entries: [status_line_entry; 5],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct status_line_entry {
    pub expanded: *mut i8,
    pub ranges: style_ranges,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style_ranges {
    pub tqh_first: *mut style_range,
    pub tqh_last: *mut *mut style_range,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style_range {
    pub type_0: style_range_type,
    pub argument: u_int,
    pub string: [i8; 16],
    pub start: u_int,
    pub end: u_int,
    pub entry: C2RustUnnamed_34,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_34 {
    pub tqe_next: *mut style_range,
    pub tqe_prev: *mut *mut style_range,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty {
    pub client: *mut client,
    pub start_timer: event,
    pub clipboard_timer: event,
    pub last_requests: time_t,
    pub sx: u_int,
    pub sy: u_int,
    pub xpixel: u_int,
    pub ypixel: u_int,
    pub cx: u_int,
    pub cy: u_int,
    pub cstyle: screen_cursor_style,
    pub ccolour: i32,
    pub oflag: i32,
    pub oox: u_int,
    pub ooy: u_int,
    pub osx: u_int,
    pub osy: u_int,
    pub mode: i32,
    pub fg: i32,
    pub bg: i32,
    pub rlower: u_int,
    pub rupper: u_int,
    pub rleft: u_int,
    pub rright: u_int,
    pub event_in: event,
    pub in_0: *mut evbuffer,
    pub event_out: event,
    pub out: *mut evbuffer,
    pub timer: event,
    pub discarded: size_t,
    pub tio: termios,
    pub cell: grid_cell,
    pub last_cell: grid_cell,
    pub flags: i32,
    pub term: *mut tty_term,
    pub mouse_last_x: u_int,
    pub mouse_last_y: u_int,
    pub mouse_last_b: u_int,
    pub mouse_drag_flag: i32,
    pub mouse_scrolling_flag: i32,
    pub mouse_slider_mpos: i32,
    pub mouse_drag_update: Option<unsafe extern "C" fn(*mut client, *mut mouse_event) -> ()>,
    pub mouse_drag_release: Option<unsafe extern "C" fn(*mut client, *mut mouse_event) -> ()>,
    pub key_timer: event,
    pub key_tree: *mut tty_key,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty_term {
    pub name: *mut i8,
    pub tty: *mut tty,
    pub features: i32,
    pub acs: [[i8; 2]; 256],
    pub codes: *mut tty_code,
    pub flags: i32,
    pub entry: C2RustUnnamed_35,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_35 {
    pub le_next: *mut tty_term,
    pub le_prev: *mut *mut tty_term,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_windows {
    pub rbh_root: *mut client_window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_window {
    pub window: u_int,
    pub pane: *mut window_pane,
    pub sx: u_int,
    pub sy: u_int,
    pub entry: C2RustUnnamed_36,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_36 {
    pub rbe_left: *mut client_window,
    pub rbe_right: *mut client_window,
    pub rbe_parent: *mut client_window,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_tree {
    pub rbh_root: *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct windows {
    pub rbh_root: *mut window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct sessions {
    pub rbh_root: *mut session,
}
pub type cmd_parse_status = u32;
pub const CMD_PARSE_SUCCESS: cmd_parse_status = 1;
pub const CMD_PARSE_ERROR: cmd_parse_status = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_parse_result {
    pub status: cmd_parse_status,
    pub cmdlist: *mut cmd_list,
    pub error: *mut i8,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_parse_input {
    pub flags: i32,
    pub file: *const i8,
    pub line: u_int,
    pub item: *mut cmdq_item,
    pub c: *mut client,
    pub fs: cmd_find_state,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct clients {
    pub tqh_first: *mut client,
    pub tqh_last: *mut *mut client,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct options_name_map {
    pub from: *const i8,
    pub to: *const i8,
}
unsafe extern "C" fn options_array_cmp(
    mut a1: *mut options_array_item,
    mut a2: *mut options_array_item,
) -> i32 {
    if (*a1).index < (*a2).index {
        return -(1 as i32);
    }
    if (*a1).index > (*a2).index {
        return 1 as i32;
    }
    return 0 as i32;
}
unsafe extern "C" fn options_array_RB_FIND(
    mut head: *mut options_array,
    mut elm: *mut options_array_item,
) -> *mut options_array_item {
    let mut tmp: *mut options_array_item = (*head).rbh_root;
    let mut comp: i32 = 0;
    while !tmp.is_null() {
        comp = options_array_cmp(elm, tmp);
        if comp < 0 as i32 {
            tmp = (*tmp).entry.rbe_left;
        } else if comp > 0 as i32 {
            tmp = (*tmp).entry.rbe_right;
        } else {
            return tmp;
        }
    }
    return std::ptr::null_mut::<options_array_item>();
}
unsafe extern "C" fn options_array_RB_REMOVE(
    mut head: *mut options_array,
    mut elm: *mut options_array_item,
) -> *mut options_array_item {
    let mut current_block: u64;
    let mut child: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    let mut parent: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    let mut old: *mut options_array_item = elm;
    let mut color: i32 = 0;
    if ((*elm).entry.rbe_left).is_null() {
        child = (*elm).entry.rbe_right;
        current_block = 7245201122033322888;
    } else if ((*elm).entry.rbe_right).is_null() {
        child = (*elm).entry.rbe_left;
        current_block = 7245201122033322888;
    } else {
        let mut left: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
        elm = (*elm).entry.rbe_right;
        loop {
            left = (*elm).entry.rbe_left;
            if left.is_null() {
                break;
            }
            elm = left;
        }
        child = (*elm).entry.rbe_right;
        parent = (*elm).entry.rbe_parent;
        color = (*elm).entry.rbe_color;
        if !child.is_null() {
            (*child).entry.rbe_parent = parent;
        }
        if !parent.is_null() {
            if (*parent).entry.rbe_left == elm {
                (*parent).entry.rbe_left = child;
            } else {
                (*parent).entry.rbe_right = child;
            }
        } else {
            (*head).rbh_root = child;
        }
        if (*elm).entry.rbe_parent == old {
            parent = elm;
        }
        (*elm).entry = (*old).entry;
        if !((*old).entry.rbe_parent).is_null() {
            if (*(*old).entry.rbe_parent).entry.rbe_left == old {
                (*(*old).entry.rbe_parent).entry.rbe_left = elm;
            } else {
                (*(*old).entry.rbe_parent).entry.rbe_right = elm;
            }
        } else {
            (*head).rbh_root = elm;
        }
        (*(*old).entry.rbe_left).entry.rbe_parent = elm;
        if !((*old).entry.rbe_right).is_null() {
            (*(*old).entry.rbe_right).entry.rbe_parent = elm;
        }
        if !parent.is_null() {
            left = parent;
            loop {
                left = (*left).entry.rbe_parent;
                if left.is_null() {
                    break;
                }
            }
        }
        current_block = 1194701948064117116;
    }
    match current_block {
        7245201122033322888 => {
            parent = (*elm).entry.rbe_parent;
            color = (*elm).entry.rbe_color;
            if !child.is_null() {
                (*child).entry.rbe_parent = parent;
            }
            if !parent.is_null() {
                if (*parent).entry.rbe_left == elm {
                    (*parent).entry.rbe_left = child;
                } else {
                    (*parent).entry.rbe_right = child;
                }
            } else {
                (*head).rbh_root = child;
            }
        }
        _ => {}
    }
    if color == 0 as i32 {
        options_array_RB_REMOVE_COLOR(head, parent, child);
    }
    return old;
}
unsafe extern "C" fn options_array_RB_REMOVE_COLOR(
    mut head: *mut options_array,
    mut parent: *mut options_array_item,
    mut elm: *mut options_array_item,
) {
    let mut tmp: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    while (elm.is_null() || (*elm).entry.rbe_color == 0 as i32) && elm != (*head).rbh_root {
        if (*parent).entry.rbe_left == elm {
            tmp = (*parent).entry.rbe_right;
            if (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 1 as i32;
                tmp = (*parent).entry.rbe_right;
                (*parent).entry.rbe_right = (*tmp).entry.rbe_left;
                if !((*parent).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_left = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                tmp = (*parent).entry.rbe_right;
            }
            if (((*tmp).entry.rbe_left).is_null()
                || (*(*tmp).entry.rbe_left).entry.rbe_color == 0 as i32)
                && (((*tmp).entry.rbe_right).is_null()
                    || (*(*tmp).entry.rbe_right).entry.rbe_color == 0 as i32)
            {
                (*tmp).entry.rbe_color = 1 as i32;
                elm = parent;
                parent = (*elm).entry.rbe_parent;
            } else {
                if ((*tmp).entry.rbe_right).is_null()
                    || (*(*tmp).entry.rbe_right).entry.rbe_color == 0 as i32
                {
                    let mut oleft: *mut options_array_item =
                        std::ptr::null_mut::<options_array_item>();
                    oleft = (*tmp).entry.rbe_left;
                    if !oleft.is_null() {
                        (*oleft).entry.rbe_color = 0 as i32;
                    }
                    (*tmp).entry.rbe_color = 1 as i32;
                    oleft = (*tmp).entry.rbe_left;
                    (*tmp).entry.rbe_left = (*oleft).entry.rbe_right;
                    if !((*tmp).entry.rbe_left).is_null() {
                        (*(*oleft).entry.rbe_right).entry.rbe_parent = tmp;
                    }
                    (*oleft).entry.rbe_parent = (*tmp).entry.rbe_parent;
                    if !((*oleft).entry.rbe_parent).is_null() {
                        if tmp == (*(*tmp).entry.rbe_parent).entry.rbe_left {
                            (*(*tmp).entry.rbe_parent).entry.rbe_left = oleft;
                        } else {
                            (*(*tmp).entry.rbe_parent).entry.rbe_right = oleft;
                        }
                    } else {
                        (*head).rbh_root = oleft;
                    }
                    (*oleft).entry.rbe_right = tmp;
                    (*tmp).entry.rbe_parent = oleft;
                    !((*oleft).entry.rbe_parent).is_null();
                    tmp = (*parent).entry.rbe_right;
                }
                (*tmp).entry.rbe_color = (*parent).entry.rbe_color;
                (*parent).entry.rbe_color = 0 as i32;
                if !((*tmp).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_color = 0 as i32;
                }
                tmp = (*parent).entry.rbe_right;
                (*parent).entry.rbe_right = (*tmp).entry.rbe_left;
                if !((*parent).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_left = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                elm = (*head).rbh_root;
                break;
            }
        } else {
            tmp = (*parent).entry.rbe_left;
            if (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 1 as i32;
                tmp = (*parent).entry.rbe_left;
                (*parent).entry.rbe_left = (*tmp).entry.rbe_right;
                if !((*parent).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_right = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                tmp = (*parent).entry.rbe_left;
            }
            if (((*tmp).entry.rbe_left).is_null()
                || (*(*tmp).entry.rbe_left).entry.rbe_color == 0 as i32)
                && (((*tmp).entry.rbe_right).is_null()
                    || (*(*tmp).entry.rbe_right).entry.rbe_color == 0 as i32)
            {
                (*tmp).entry.rbe_color = 1 as i32;
                elm = parent;
                parent = (*elm).entry.rbe_parent;
            } else {
                if ((*tmp).entry.rbe_left).is_null()
                    || (*(*tmp).entry.rbe_left).entry.rbe_color == 0 as i32
                {
                    let mut oright: *mut options_array_item =
                        std::ptr::null_mut::<options_array_item>();
                    oright = (*tmp).entry.rbe_right;
                    if !oright.is_null() {
                        (*oright).entry.rbe_color = 0 as i32;
                    }
                    (*tmp).entry.rbe_color = 1 as i32;
                    oright = (*tmp).entry.rbe_right;
                    (*tmp).entry.rbe_right = (*oright).entry.rbe_left;
                    if !((*tmp).entry.rbe_right).is_null() {
                        (*(*oright).entry.rbe_left).entry.rbe_parent = tmp;
                    }
                    (*oright).entry.rbe_parent = (*tmp).entry.rbe_parent;
                    if !((*oright).entry.rbe_parent).is_null() {
                        if tmp == (*(*tmp).entry.rbe_parent).entry.rbe_left {
                            (*(*tmp).entry.rbe_parent).entry.rbe_left = oright;
                        } else {
                            (*(*tmp).entry.rbe_parent).entry.rbe_right = oright;
                        }
                    } else {
                        (*head).rbh_root = oright;
                    }
                    (*oright).entry.rbe_left = tmp;
                    (*tmp).entry.rbe_parent = oright;
                    !((*oright).entry.rbe_parent).is_null();
                    tmp = (*parent).entry.rbe_left;
                }
                (*tmp).entry.rbe_color = (*parent).entry.rbe_color;
                (*parent).entry.rbe_color = 0 as i32;
                if !((*tmp).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_color = 0 as i32;
                }
                tmp = (*parent).entry.rbe_left;
                (*parent).entry.rbe_left = (*tmp).entry.rbe_right;
                if !((*parent).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_right = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                elm = (*head).rbh_root;
                break;
            }
        }
    }
    if !elm.is_null() {
        (*elm).entry.rbe_color = 0 as i32;
    }
}
unsafe extern "C" fn options_array_RB_NEXT(
    mut elm: *mut options_array_item,
) -> *mut options_array_item {
    if !((*elm).entry.rbe_right).is_null() {
        elm = (*elm).entry.rbe_right;
        while !((*elm).entry.rbe_left).is_null() {
            elm = (*elm).entry.rbe_left;
        }
    } else if !((*elm).entry.rbe_parent).is_null()
        && elm == (*(*elm).entry.rbe_parent).entry.rbe_left
    {
        elm = (*elm).entry.rbe_parent;
    } else {
        while !((*elm).entry.rbe_parent).is_null()
            && elm == (*(*elm).entry.rbe_parent).entry.rbe_right
        {
            elm = (*elm).entry.rbe_parent;
        }
        elm = (*elm).entry.rbe_parent;
    }
    return elm;
}
unsafe extern "C" fn options_array_RB_MINMAX(
    mut head: *mut options_array,
    mut val: i32,
) -> *mut options_array_item {
    let mut tmp: *mut options_array_item = (*head).rbh_root;
    let mut parent: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    while !tmp.is_null() {
        parent = tmp;
        if val < 0 as i32 {
            tmp = (*tmp).entry.rbe_left;
        } else {
            tmp = (*tmp).entry.rbe_right;
        }
    }
    return parent;
}
unsafe extern "C" fn options_array_RB_INSERT(
    mut head: *mut options_array,
    mut elm: *mut options_array_item,
) -> *mut options_array_item {
    let mut tmp: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    let mut parent: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    let mut comp: i32 = 0 as i32;
    tmp = (*head).rbh_root;
    while !tmp.is_null() {
        parent = tmp;
        comp = options_array_cmp(elm, parent);
        if comp < 0 as i32 {
            tmp = (*tmp).entry.rbe_left;
        } else if comp > 0 as i32 {
            tmp = (*tmp).entry.rbe_right;
        } else {
            return tmp;
        }
    }
    (*elm).entry.rbe_parent = parent;
    (*elm).entry.rbe_right = std::ptr::null_mut::<options_array_item>();
    (*elm).entry.rbe_left = (*elm).entry.rbe_right;
    (*elm).entry.rbe_color = 1 as i32;
    if !parent.is_null() {
        if comp < 0 as i32 {
            (*parent).entry.rbe_left = elm;
        } else {
            (*parent).entry.rbe_right = elm;
        }
    } else {
        (*head).rbh_root = elm;
    }
    options_array_RB_INSERT_COLOR(head, elm);
    return std::ptr::null_mut::<options_array_item>();
}
unsafe extern "C" fn options_array_RB_INSERT_COLOR(
    mut head: *mut options_array,
    mut elm: *mut options_array_item,
) {
    let mut parent: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    let mut gparent: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    let mut tmp: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    loop {
        parent = (*elm).entry.rbe_parent;
        if parent.is_null() || (*parent).entry.rbe_color != 1 as i32 {
            break;
        }
        gparent = (*parent).entry.rbe_parent;
        if parent == (*gparent).entry.rbe_left {
            tmp = (*gparent).entry.rbe_right;
            if !tmp.is_null() && (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                elm = gparent;
            } else {
                if (*parent).entry.rbe_right == elm {
                    tmp = (*parent).entry.rbe_right;
                    (*parent).entry.rbe_right = (*tmp).entry.rbe_left;
                    if !((*parent).entry.rbe_right).is_null() {
                        (*(*tmp).entry.rbe_left).entry.rbe_parent = parent;
                    }
                    (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                    if !((*tmp).entry.rbe_parent).is_null() {
                        if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                            (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                        } else {
                            (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                        }
                    } else {
                        (*head).rbh_root = tmp;
                    }
                    (*tmp).entry.rbe_left = parent;
                    (*parent).entry.rbe_parent = tmp;
                    !((*tmp).entry.rbe_parent).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                tmp = (*gparent).entry.rbe_left;
                (*gparent).entry.rbe_left = (*tmp).entry.rbe_right;
                if !((*gparent).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_parent = gparent;
                }
                (*tmp).entry.rbe_parent = (*gparent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if gparent == (*(*gparent).entry.rbe_parent).entry.rbe_left {
                        (*(*gparent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*gparent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_right = gparent;
                (*gparent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
            }
        } else {
            tmp = (*gparent).entry.rbe_left;
            if !tmp.is_null() && (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                elm = gparent;
            } else {
                if (*parent).entry.rbe_left == elm {
                    tmp = (*parent).entry.rbe_left;
                    (*parent).entry.rbe_left = (*tmp).entry.rbe_right;
                    if !((*parent).entry.rbe_left).is_null() {
                        (*(*tmp).entry.rbe_right).entry.rbe_parent = parent;
                    }
                    (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                    if !((*tmp).entry.rbe_parent).is_null() {
                        if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                            (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                        } else {
                            (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                        }
                    } else {
                        (*head).rbh_root = tmp;
                    }
                    (*tmp).entry.rbe_right = parent;
                    (*parent).entry.rbe_parent = tmp;
                    !((*tmp).entry.rbe_parent).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                tmp = (*gparent).entry.rbe_right;
                (*gparent).entry.rbe_right = (*tmp).entry.rbe_left;
                if !((*gparent).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_parent = gparent;
                }
                (*tmp).entry.rbe_parent = (*gparent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if gparent == (*(*gparent).entry.rbe_parent).entry.rbe_left {
                        (*(*gparent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*gparent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_left = gparent;
                (*gparent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
            }
        }
    }
    (*(*head).rbh_root).entry.rbe_color = 0 as i32;
}
unsafe extern "C" fn options_tree_RB_FIND(
    mut head: *mut options_tree,
    mut elm: *mut options_entry,
) -> *mut options_entry {
    let mut tmp: *mut options_entry = (*head).rbh_root;
    let mut comp: i32 = 0;
    while !tmp.is_null() {
        comp = options_cmp(elm, tmp);
        if comp < 0 as i32 {
            tmp = (*tmp).entry.rbe_left;
        } else if comp > 0 as i32 {
            tmp = (*tmp).entry.rbe_right;
        } else {
            return tmp;
        }
    }
    return std::ptr::null_mut::<options_entry>();
}
unsafe extern "C" fn options_tree_RB_MINMAX(
    mut head: *mut options_tree,
    mut val: i32,
) -> *mut options_entry {
    let mut tmp: *mut options_entry = (*head).rbh_root;
    let mut parent: *mut options_entry = std::ptr::null_mut::<options_entry>();
    while !tmp.is_null() {
        parent = tmp;
        if val < 0 as i32 {
            tmp = (*tmp).entry.rbe_left;
        } else {
            tmp = (*tmp).entry.rbe_right;
        }
    }
    return parent;
}
unsafe extern "C" fn options_tree_RB_REMOVE(
    mut head: *mut options_tree,
    mut elm: *mut options_entry,
) -> *mut options_entry {
    let mut current_block: u64;
    let mut child: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut parent: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut old: *mut options_entry = elm;
    let mut color: i32 = 0;
    if ((*elm).entry.rbe_left).is_null() {
        child = (*elm).entry.rbe_right;
        current_block = 7245201122033322888;
    } else if ((*elm).entry.rbe_right).is_null() {
        child = (*elm).entry.rbe_left;
        current_block = 7245201122033322888;
    } else {
        let mut left: *mut options_entry = std::ptr::null_mut::<options_entry>();
        elm = (*elm).entry.rbe_right;
        loop {
            left = (*elm).entry.rbe_left;
            if left.is_null() {
                break;
            }
            elm = left;
        }
        child = (*elm).entry.rbe_right;
        parent = (*elm).entry.rbe_parent;
        color = (*elm).entry.rbe_color;
        if !child.is_null() {
            (*child).entry.rbe_parent = parent;
        }
        if !parent.is_null() {
            if (*parent).entry.rbe_left == elm {
                (*parent).entry.rbe_left = child;
            } else {
                (*parent).entry.rbe_right = child;
            }
        } else {
            (*head).rbh_root = child;
        }
        if (*elm).entry.rbe_parent == old {
            parent = elm;
        }
        (*elm).entry = (*old).entry;
        if !((*old).entry.rbe_parent).is_null() {
            if (*(*old).entry.rbe_parent).entry.rbe_left == old {
                (*(*old).entry.rbe_parent).entry.rbe_left = elm;
            } else {
                (*(*old).entry.rbe_parent).entry.rbe_right = elm;
            }
        } else {
            (*head).rbh_root = elm;
        }
        (*(*old).entry.rbe_left).entry.rbe_parent = elm;
        if !((*old).entry.rbe_right).is_null() {
            (*(*old).entry.rbe_right).entry.rbe_parent = elm;
        }
        if !parent.is_null() {
            left = parent;
            loop {
                left = (*left).entry.rbe_parent;
                if left.is_null() {
                    break;
                }
            }
        }
        current_block = 8429121645885805952;
    }
    match current_block {
        7245201122033322888 => {
            parent = (*elm).entry.rbe_parent;
            color = (*elm).entry.rbe_color;
            if !child.is_null() {
                (*child).entry.rbe_parent = parent;
            }
            if !parent.is_null() {
                if (*parent).entry.rbe_left == elm {
                    (*parent).entry.rbe_left = child;
                } else {
                    (*parent).entry.rbe_right = child;
                }
            } else {
                (*head).rbh_root = child;
            }
        }
        _ => {}
    }
    if color == 0 as i32 {
        options_tree_RB_REMOVE_COLOR(head, parent, child);
    }
    return old;
}
unsafe extern "C" fn options_tree_RB_REMOVE_COLOR(
    mut head: *mut options_tree,
    mut parent: *mut options_entry,
    mut elm: *mut options_entry,
) {
    let mut tmp: *mut options_entry = std::ptr::null_mut::<options_entry>();
    while (elm.is_null() || (*elm).entry.rbe_color == 0 as i32) && elm != (*head).rbh_root {
        if (*parent).entry.rbe_left == elm {
            tmp = (*parent).entry.rbe_right;
            if (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 1 as i32;
                tmp = (*parent).entry.rbe_right;
                (*parent).entry.rbe_right = (*tmp).entry.rbe_left;
                if !((*parent).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_left = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                tmp = (*parent).entry.rbe_right;
            }
            if (((*tmp).entry.rbe_left).is_null()
                || (*(*tmp).entry.rbe_left).entry.rbe_color == 0 as i32)
                && (((*tmp).entry.rbe_right).is_null()
                    || (*(*tmp).entry.rbe_right).entry.rbe_color == 0 as i32)
            {
                (*tmp).entry.rbe_color = 1 as i32;
                elm = parent;
                parent = (*elm).entry.rbe_parent;
            } else {
                if ((*tmp).entry.rbe_right).is_null()
                    || (*(*tmp).entry.rbe_right).entry.rbe_color == 0 as i32
                {
                    let mut oleft: *mut options_entry = std::ptr::null_mut::<options_entry>();
                    oleft = (*tmp).entry.rbe_left;
                    if !oleft.is_null() {
                        (*oleft).entry.rbe_color = 0 as i32;
                    }
                    (*tmp).entry.rbe_color = 1 as i32;
                    oleft = (*tmp).entry.rbe_left;
                    (*tmp).entry.rbe_left = (*oleft).entry.rbe_right;
                    if !((*tmp).entry.rbe_left).is_null() {
                        (*(*oleft).entry.rbe_right).entry.rbe_parent = tmp;
                    }
                    (*oleft).entry.rbe_parent = (*tmp).entry.rbe_parent;
                    if !((*oleft).entry.rbe_parent).is_null() {
                        if tmp == (*(*tmp).entry.rbe_parent).entry.rbe_left {
                            (*(*tmp).entry.rbe_parent).entry.rbe_left = oleft;
                        } else {
                            (*(*tmp).entry.rbe_parent).entry.rbe_right = oleft;
                        }
                    } else {
                        (*head).rbh_root = oleft;
                    }
                    (*oleft).entry.rbe_right = tmp;
                    (*tmp).entry.rbe_parent = oleft;
                    !((*oleft).entry.rbe_parent).is_null();
                    tmp = (*parent).entry.rbe_right;
                }
                (*tmp).entry.rbe_color = (*parent).entry.rbe_color;
                (*parent).entry.rbe_color = 0 as i32;
                if !((*tmp).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_color = 0 as i32;
                }
                tmp = (*parent).entry.rbe_right;
                (*parent).entry.rbe_right = (*tmp).entry.rbe_left;
                if !((*parent).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_left = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                elm = (*head).rbh_root;
                break;
            }
        } else {
            tmp = (*parent).entry.rbe_left;
            if (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 1 as i32;
                tmp = (*parent).entry.rbe_left;
                (*parent).entry.rbe_left = (*tmp).entry.rbe_right;
                if !((*parent).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_right = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                tmp = (*parent).entry.rbe_left;
            }
            if (((*tmp).entry.rbe_left).is_null()
                || (*(*tmp).entry.rbe_left).entry.rbe_color == 0 as i32)
                && (((*tmp).entry.rbe_right).is_null()
                    || (*(*tmp).entry.rbe_right).entry.rbe_color == 0 as i32)
            {
                (*tmp).entry.rbe_color = 1 as i32;
                elm = parent;
                parent = (*elm).entry.rbe_parent;
            } else {
                if ((*tmp).entry.rbe_left).is_null()
                    || (*(*tmp).entry.rbe_left).entry.rbe_color == 0 as i32
                {
                    let mut oright: *mut options_entry = std::ptr::null_mut::<options_entry>();
                    oright = (*tmp).entry.rbe_right;
                    if !oright.is_null() {
                        (*oright).entry.rbe_color = 0 as i32;
                    }
                    (*tmp).entry.rbe_color = 1 as i32;
                    oright = (*tmp).entry.rbe_right;
                    (*tmp).entry.rbe_right = (*oright).entry.rbe_left;
                    if !((*tmp).entry.rbe_right).is_null() {
                        (*(*oright).entry.rbe_left).entry.rbe_parent = tmp;
                    }
                    (*oright).entry.rbe_parent = (*tmp).entry.rbe_parent;
                    if !((*oright).entry.rbe_parent).is_null() {
                        if tmp == (*(*tmp).entry.rbe_parent).entry.rbe_left {
                            (*(*tmp).entry.rbe_parent).entry.rbe_left = oright;
                        } else {
                            (*(*tmp).entry.rbe_parent).entry.rbe_right = oright;
                        }
                    } else {
                        (*head).rbh_root = oright;
                    }
                    (*oright).entry.rbe_left = tmp;
                    (*tmp).entry.rbe_parent = oright;
                    !((*oright).entry.rbe_parent).is_null();
                    tmp = (*parent).entry.rbe_left;
                }
                (*tmp).entry.rbe_color = (*parent).entry.rbe_color;
                (*parent).entry.rbe_color = 0 as i32;
                if !((*tmp).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_color = 0 as i32;
                }
                tmp = (*parent).entry.rbe_left;
                (*parent).entry.rbe_left = (*tmp).entry.rbe_right;
                if !((*parent).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_right = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                elm = (*head).rbh_root;
                break;
            }
        }
    }
    if !elm.is_null() {
        (*elm).entry.rbe_color = 0 as i32;
    }
}
unsafe extern "C" fn options_tree_RB_NEXT(mut elm: *mut options_entry) -> *mut options_entry {
    if !((*elm).entry.rbe_right).is_null() {
        elm = (*elm).entry.rbe_right;
        while !((*elm).entry.rbe_left).is_null() {
            elm = (*elm).entry.rbe_left;
        }
    } else if !((*elm).entry.rbe_parent).is_null()
        && elm == (*(*elm).entry.rbe_parent).entry.rbe_left
    {
        elm = (*elm).entry.rbe_parent;
    } else {
        while !((*elm).entry.rbe_parent).is_null()
            && elm == (*(*elm).entry.rbe_parent).entry.rbe_right
        {
            elm = (*elm).entry.rbe_parent;
        }
        elm = (*elm).entry.rbe_parent;
    }
    return elm;
}
unsafe extern "C" fn options_tree_RB_INSERT_COLOR(
    mut head: *mut options_tree,
    mut elm: *mut options_entry,
) {
    let mut parent: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut gparent: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut tmp: *mut options_entry = std::ptr::null_mut::<options_entry>();
    loop {
        parent = (*elm).entry.rbe_parent;
        if parent.is_null() || (*parent).entry.rbe_color != 1 as i32 {
            break;
        }
        gparent = (*parent).entry.rbe_parent;
        if parent == (*gparent).entry.rbe_left {
            tmp = (*gparent).entry.rbe_right;
            if !tmp.is_null() && (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                elm = gparent;
            } else {
                if (*parent).entry.rbe_right == elm {
                    tmp = (*parent).entry.rbe_right;
                    (*parent).entry.rbe_right = (*tmp).entry.rbe_left;
                    if !((*parent).entry.rbe_right).is_null() {
                        (*(*tmp).entry.rbe_left).entry.rbe_parent = parent;
                    }
                    (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                    if !((*tmp).entry.rbe_parent).is_null() {
                        if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                            (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                        } else {
                            (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                        }
                    } else {
                        (*head).rbh_root = tmp;
                    }
                    (*tmp).entry.rbe_left = parent;
                    (*parent).entry.rbe_parent = tmp;
                    !((*tmp).entry.rbe_parent).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                tmp = (*gparent).entry.rbe_left;
                (*gparent).entry.rbe_left = (*tmp).entry.rbe_right;
                if !((*gparent).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_parent = gparent;
                }
                (*tmp).entry.rbe_parent = (*gparent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if gparent == (*(*gparent).entry.rbe_parent).entry.rbe_left {
                        (*(*gparent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*gparent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_right = gparent;
                (*gparent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
            }
        } else {
            tmp = (*gparent).entry.rbe_left;
            if !tmp.is_null() && (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                elm = gparent;
            } else {
                if (*parent).entry.rbe_left == elm {
                    tmp = (*parent).entry.rbe_left;
                    (*parent).entry.rbe_left = (*tmp).entry.rbe_right;
                    if !((*parent).entry.rbe_left).is_null() {
                        (*(*tmp).entry.rbe_right).entry.rbe_parent = parent;
                    }
                    (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                    if !((*tmp).entry.rbe_parent).is_null() {
                        if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                            (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                        } else {
                            (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                        }
                    } else {
                        (*head).rbh_root = tmp;
                    }
                    (*tmp).entry.rbe_right = parent;
                    (*parent).entry.rbe_parent = tmp;
                    !((*tmp).entry.rbe_parent).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                tmp = (*gparent).entry.rbe_right;
                (*gparent).entry.rbe_right = (*tmp).entry.rbe_left;
                if !((*gparent).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_parent = gparent;
                }
                (*tmp).entry.rbe_parent = (*gparent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if gparent == (*(*gparent).entry.rbe_parent).entry.rbe_left {
                        (*(*gparent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*gparent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_left = gparent;
                (*gparent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
            }
        }
    }
    (*(*head).rbh_root).entry.rbe_color = 0 as i32;
}
unsafe extern "C" fn options_tree_RB_INSERT(
    mut head: *mut options_tree,
    mut elm: *mut options_entry,
) -> *mut options_entry {
    let mut tmp: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut parent: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut comp: i32 = 0 as i32;
    tmp = (*head).rbh_root;
    while !tmp.is_null() {
        parent = tmp;
        comp = options_cmp(elm, parent);
        if comp < 0 as i32 {
            tmp = (*tmp).entry.rbe_left;
        } else if comp > 0 as i32 {
            tmp = (*tmp).entry.rbe_right;
        } else {
            return tmp;
        }
    }
    (*elm).entry.rbe_parent = parent;
    (*elm).entry.rbe_right = std::ptr::null_mut::<options_entry>();
    (*elm).entry.rbe_left = (*elm).entry.rbe_right;
    (*elm).entry.rbe_color = 1 as i32;
    if !parent.is_null() {
        if comp < 0 as i32 {
            (*parent).entry.rbe_left = elm;
        } else {
            (*parent).entry.rbe_right = elm;
        }
    } else {
        (*head).rbh_root = elm;
    }
    options_tree_RB_INSERT_COLOR(head, elm);
    return std::ptr::null_mut::<options_entry>();
}
unsafe extern "C" fn options_cmp(
    mut lhs: *mut options_entry,
    mut rhs: *mut options_entry,
) -> i32 {
    return strcmp((*lhs).name, (*rhs).name);
}
unsafe extern "C" fn options_map_name(mut name: *const i8) -> *const i8 {
    let mut map: *const options_name_map = std::ptr::null::<options_name_map>();
    map = options_other_names.as_ptr();
    while !((*map).from).is_null() {
        if strcmp((*map).from, name) == 0 as i32 {
            return (*map).to;
        }
        map = map.offset(1);
    }
    return name;
}
unsafe extern "C" fn options_parent_table_entry(
    mut oo: *mut options,
    mut s: *const i8,
) -> *const options_table_entry {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    if ((*oo).parent).is_null() {
        fatalx(
            b"no parent options for %s\0" as *const u8 as *const i8,
            s,
        );
    }
    o = options_get((*oo).parent, s);
    if o.is_null() {
        fatalx(
            b"%s not in parent options\0" as *const u8 as *const i8,
            s,
        );
    }
    return (*o).tableentry;
}
unsafe extern "C" fn options_value_free(mut o: *mut options_entry, mut ov: *mut options_value) {
    if ((*o).tableentry).is_null()
        || (*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_STRING as i32 as u32
    {
        free((*ov).string as *mut libc::c_void);
    }
    if !((*o).tableentry).is_null()
        && (*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_COMMAND as i32 as u32
        && !((*ov).cmdlist).is_null()
    {
        cmd_list_free((*ov).cmdlist);
    }
}
unsafe extern "C" fn options_value_to_string(
    mut o: *mut options_entry,
    mut ov: *mut options_value,
    mut numeric: i32,
) -> *mut i8 {
    let mut s: *mut i8 = std::ptr::null_mut::<i8>();
    if !((*o).tableentry).is_null()
        && (*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_COMMAND as i32 as u32
    {
        return cmd_list_print((*ov).cmdlist, 0 as i32);
    }
    if !((*o).tableentry).is_null()
        && ((*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_NUMBER as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_KEY as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_COLOUR as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_FLAG as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_CHOICE as i32 as u32)
    {
        match (*(*o).tableentry).type_0 as u32 {
            1 => {
                xasprintf(
                    &mut s as *mut *mut i8,
                    b"%lld\0" as *const u8 as *const i8,
                    (*ov).number,
                );
            }
            2 => {
                s = xstrdup(key_string_lookup_key(
                    (*ov).number as key_code,
                    0 as i32,
                ));
            }
            3 => {
                s = xstrdup(colour_tostring((*ov).number as i32));
            }
            4 => {
                if numeric != 0 {
                    xasprintf(
                        &mut s as *mut *mut i8,
                        b"%lld\0" as *const u8 as *const i8,
                        (*ov).number,
                    );
                } else {
                    s = xstrdup(if (*ov).number != 0 {
                        b"on\0" as *const u8 as *const i8
                    } else {
                        b"off\0" as *const u8 as *const i8
                    });
                }
            }
            5 => {
                s = xstrdup(*((*(*o).tableentry).choices).offset((*ov).number as isize));
            }
            _ => {
                fatalx(b"not a number option type\0" as *const u8 as *const i8);
            }
        }
        return s;
    }
    if ((*o).tableentry).is_null()
        || (*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_STRING as i32 as u32
    {
        return xstrdup((*ov).string);
    }
    return xstrdup(b"\0" as *const u8 as *const i8);
}
#[no_mangle]
pub unsafe extern "C" fn options_create(mut parent: *mut options) -> *mut options {
    let mut oo: *mut options = std::ptr::null_mut::<options>();
    oo = xcalloc(
        1 as i32 as size_t,
        ::core::mem::size_of::<options>() as u64,
    ) as *mut options;
    (*oo).tree.rbh_root = std::ptr::null_mut::<options_entry>();
    (*oo).parent = parent;
    return oo;
}
#[no_mangle]
pub unsafe extern "C" fn options_free(mut oo: *mut options) {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut tmp: *mut options_entry = std::ptr::null_mut::<options_entry>();
    o = options_tree_RB_MINMAX(&mut (*oo).tree, -(1 as i32));
    while !o.is_null() && {
        tmp = options_tree_RB_NEXT(o);
        1 as i32 != 0
    } {
        options_remove(o);
        o = tmp;
    }
    free(oo as *mut libc::c_void);
}
#[no_mangle]
pub unsafe extern "C" fn options_get_parent(mut oo: *mut options) -> *mut options {
    return (*oo).parent;
}
#[no_mangle]
pub unsafe extern "C" fn options_set_parent(mut oo: *mut options, mut parent: *mut options) {
    (*oo).parent = parent;
}
#[no_mangle]
pub unsafe extern "C" fn options_first(mut oo: *mut options) -> *mut options_entry {
    return options_tree_RB_MINMAX(&mut (*oo).tree, -(1 as i32));
}
#[no_mangle]
pub unsafe extern "C" fn options_next(mut o: *mut options_entry) -> *mut options_entry {
    return options_tree_RB_NEXT(o);
}
#[no_mangle]
pub unsafe extern "C" fn options_get_only(
    mut oo: *mut options,
    mut name: *const i8,
) -> *mut options_entry {
    let mut o: options_entry = {
        let mut init = options_entry {
            owner: std::ptr::null_mut::<options>(),
            name: name,
            tableentry: std::ptr::null::<options_table_entry>(),
            value: options_value {
                string: std::ptr::null_mut::<i8>(),
            },
            cached: 0,
            style: style {
                gc: grid_cell {
                    data: utf8_data {
                        data: [0; 21],
                        have: 0,
                        size: 0,
                        width: 0,
                    },
                    attr: 0,
                    flags: 0,
                    fg: 0,
                    bg: 0,
                    us: 0,
                    link: 0,
                },
                ignore: 0,
                fill: 0,
                align: STYLE_ALIGN_DEFAULT,
                list: STYLE_LIST_OFF,
                range_type: STYLE_RANGE_NONE,
                range_argument: 0,
                range_string: [0; 16],
                width: 0,
                pad: 0,
                default_type: STYLE_DEFAULT_BASE,
            },
            entry: C2RustUnnamed_15 {
                rbe_left: std::ptr::null_mut::<options_entry>(),
                rbe_right: std::ptr::null_mut::<options_entry>(),
                rbe_parent: std::ptr::null_mut::<options_entry>(),
                rbe_color: 0,
            },
        };
        init
    };
    let mut found: *mut options_entry = std::ptr::null_mut::<options_entry>();
    found = options_tree_RB_FIND(&mut (*oo).tree, &mut o);
    if found.is_null() {
        o.name = options_map_name(name);
        return options_tree_RB_FIND(&mut (*oo).tree, &mut o);
    }
    return found;
}
#[no_mangle]
pub unsafe extern "C" fn options_get(
    mut oo: *mut options,
    mut name: *const i8,
) -> *mut options_entry {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    o = options_get_only(oo, name);
    while o.is_null() {
        oo = (*oo).parent;
        if oo.is_null() {
            break;
        }
        o = options_get_only(oo, name);
    }
    return o;
}
#[no_mangle]
pub unsafe extern "C" fn options_empty(
    mut oo: *mut options,
    mut oe: *const options_table_entry,
) -> *mut options_entry {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    o = options_add(oo, (*oe).name);
    (*o).tableentry = oe;
    if (*oe).flags & 0x1 as i32 != 0 {
        (*o).value.array.rbh_root = std::ptr::null_mut::<options_array_item>();
    }
    return o;
}
#[no_mangle]
pub unsafe extern "C" fn options_default(
    mut oo: *mut options,
    mut oe: *const options_table_entry,
) -> *mut options_entry {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut ov: *mut options_value = std::ptr::null_mut::<options_value>();
    let mut i: u_int = 0;
    o = options_empty(oo, oe);
    ov = &mut (*o).value;
    if (*oe).flags & 0x1 as i32 != 0 {
        if ((*oe).default_arr).is_null() {
            options_array_assign(
                o,
                (*oe).default_str,
                std::ptr::null_mut::<*mut i8>(),
            );
            return o;
        }
        i = 0 as i32 as u_int;
        while !(*((*oe).default_arr).offset(i as isize)).is_null() {
            options_array_set(
                o,
                i,
                *((*oe).default_arr).offset(i as isize),
                0 as i32,
                std::ptr::null_mut::<*mut i8>(),
            );
            i = i.wrapping_add(1);
        }
        return o;
    }
    match (*oe).type_0 as u32 {
        0 => {
            (*ov).string = xstrdup((*oe).default_str);
        }
        _ => {
            (*ov).number = (*oe).default_num;
        }
    }
    return o;
}
#[no_mangle]
pub unsafe extern "C" fn options_default_to_string(
    mut oe: *const options_table_entry,
) -> *mut i8 {
    let mut s: *mut i8 = std::ptr::null_mut::<i8>();
    match (*oe).type_0 as u32 {
        0 | 6 => {
            s = xstrdup((*oe).default_str);
        }
        1 => {
            xasprintf(
                &mut s as *mut *mut i8,
                b"%lld\0" as *const u8 as *const i8,
                (*oe).default_num,
            );
        }
        2 => {
            s = xstrdup(key_string_lookup_key(
                (*oe).default_num as key_code,
                0 as i32,
            ));
        }
        3 => {
            s = xstrdup(colour_tostring((*oe).default_num as i32));
        }
        4 => {
            s = xstrdup(if (*oe).default_num != 0 {
                b"on\0" as *const u8 as *const i8
            } else {
                b"off\0" as *const u8 as *const i8
            });
        }
        5 => {
            s = xstrdup(*((*oe).choices).offset((*oe).default_num as isize));
        }
        _ => {
            fatalx(b"unknown option type\0" as *const u8 as *const i8);
        }
    }
    return s;
}
unsafe extern "C" fn options_add(
    mut oo: *mut options,
    mut name: *const i8,
) -> *mut options_entry {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    o = options_get_only(oo, name);
    if !o.is_null() {
        options_remove(o);
    }
    o = xcalloc(
        1 as i32 as size_t,
        ::core::mem::size_of::<options_entry>() as u64,
    ) as *mut options_entry;
    (*o).owner = oo;
    (*o).name = xstrdup(name);
    options_tree_RB_INSERT(&mut (*oo).tree, o);
    return o;
}
unsafe extern "C" fn options_remove(mut o: *mut options_entry) {
    let mut oo: *mut options = (*o).owner;
    if !((*o).tableentry).is_null() && (*(*o).tableentry).flags & 0x1 as i32 != 0 {
        options_array_clear(o);
    } else {
        options_value_free(o, &mut (*o).value);
    }
    options_tree_RB_REMOVE(&mut (*oo).tree, o);
    free((*o).name as *mut libc::c_void);
    free(o as *mut libc::c_void);
}
#[no_mangle]
pub unsafe extern "C" fn options_name(mut o: *mut options_entry) -> *const i8 {
    return (*o).name;
}
#[no_mangle]
pub unsafe extern "C" fn options_owner(mut o: *mut options_entry) -> *mut options {
    return (*o).owner;
}
#[no_mangle]
pub unsafe extern "C" fn options_table_entry(
    mut o: *mut options_entry,
) -> *const options_table_entry {
    return (*o).tableentry;
}
unsafe extern "C" fn options_array_item(
    mut o: *mut options_entry,
    mut idx: u_int,
) -> *mut options_array_item {
    let mut a: options_array_item = options_array_item {
        index: 0,
        value: options_value {
            string: std::ptr::null_mut::<i8>(),
        },
        entry: C2RustUnnamed_16 {
            rbe_left: std::ptr::null_mut::<options_array_item>(),
            rbe_right: std::ptr::null_mut::<options_array_item>(),
            rbe_parent: std::ptr::null_mut::<options_array_item>(),
            rbe_color: 0,
        },
    };
    a.index = idx;
    return options_array_RB_FIND(&mut (*o).value.array, &mut a);
}
unsafe extern "C" fn options_array_new(
    mut o: *mut options_entry,
    mut idx: u_int,
) -> *mut options_array_item {
    let mut a: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    a = xcalloc(
        1 as i32 as size_t,
        ::core::mem::size_of::<options_array_item>() as u64,
    ) as *mut options_array_item;
    (*a).index = idx;
    options_array_RB_INSERT(&mut (*o).value.array, a);
    return a;
}
unsafe extern "C" fn options_array_free(mut o: *mut options_entry, mut a: *mut options_array_item) {
    options_value_free(o, &mut (*a).value);
    options_array_RB_REMOVE(&mut (*o).value.array, a);
    free(a as *mut libc::c_void);
}
#[no_mangle]
pub unsafe extern "C" fn options_array_clear(mut o: *mut options_entry) {
    let mut a: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    let mut a1: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    if ((*o).tableentry).is_null() || (*(*o).tableentry).flags & 0x1 as i32 == 0 {
        return;
    }
    a = options_array_RB_MINMAX(&mut (*o).value.array, -(1 as i32));
    while !a.is_null() && {
        a1 = options_array_RB_NEXT(a);
        1 as i32 != 0
    } {
        options_array_free(o, a);
        a = a1;
    }
}
#[no_mangle]
pub unsafe extern "C" fn options_array_get(
    mut o: *mut options_entry,
    mut idx: u_int,
) -> *mut options_value {
    let mut a: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    if ((*o).tableentry).is_null() || (*(*o).tableentry).flags & 0x1 as i32 == 0 {
        return std::ptr::null_mut::<options_value>();
    }
    a = options_array_item(o, idx);
    if a.is_null() {
        return std::ptr::null_mut::<options_value>();
    }
    return &mut (*a).value;
}
#[no_mangle]
pub unsafe extern "C" fn options_array_set(
    mut o: *mut options_entry,
    mut idx: u_int,
    mut value: *const i8,
    mut append: i32,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut a: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    let mut new: *mut i8 = std::ptr::null_mut::<i8>();
    let mut pr: *mut cmd_parse_result = std::ptr::null_mut::<cmd_parse_result>();
    let mut number: i64 = 0;
    if ((*o).tableentry).is_null() || (*(*o).tableentry).flags & 0x1 as i32 == 0 {
        if !cause.is_null() {
            *cause = xstrdup(b"not an array\0" as *const u8 as *const i8);
        }
        return -(1 as i32);
    }
    if value.is_null() {
        a = options_array_item(o, idx);
        if !a.is_null() {
            options_array_free(o, a);
        }
        return 0 as i32;
    }
    if !((*o).tableentry).is_null()
        && (*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_COMMAND as i32 as u32
    {
        pr = cmd_parse_from_string(value, std::ptr::null_mut::<cmd_parse_input>());
        match (*pr).status as u32 {
            0 => {
                if !cause.is_null() {
                    *cause = (*pr).error;
                } else {
                    free((*pr).error as *mut libc::c_void);
                }
                return -(1 as i32);
            }
            1 | _ => {}
        }
        a = options_array_item(o, idx);
        if a.is_null() {
            a = options_array_new(o, idx);
        } else {
            options_value_free(o, &mut (*a).value);
        }
        (*a).value.cmdlist = (*pr).cmdlist;
        return 0 as i32;
    }
    if ((*o).tableentry).is_null()
        || (*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_STRING as i32 as u32
    {
        a = options_array_item(o, idx);
        if !a.is_null() && append != 0 {
            xasprintf(
                &mut new as *mut *mut i8,
                b"%s%s\0" as *const u8 as *const i8,
                (*a).value.string,
                value,
            );
        } else {
            new = xstrdup(value);
        }
        if a.is_null() {
            a = options_array_new(o, idx);
        } else {
            options_value_free(o, &mut (*a).value);
        }
        (*a).value.string = new;
        return 0 as i32;
    }
    if (*(*o).tableentry).type_0 as u32
        == OPTIONS_TABLE_COLOUR as i32 as u32
    {
        number = colour_fromstring(value) as i64;
        if number == -(1 as i32) as i64 {
            xasprintf(
                cause,
                b"bad colour: %s\0" as *const u8 as *const i8,
                value,
            );
            return -(1 as i32);
        }
        a = options_array_item(o, idx);
        if a.is_null() {
            a = options_array_new(o, idx);
        } else {
            options_value_free(o, &mut (*a).value);
        }
        (*a).value.number = number;
        return 0 as i32;
    }
    if !cause.is_null() {
        *cause = xstrdup(b"wrong array type\0" as *const u8 as *const i8);
    }
    return -(1 as i32);
}
#[no_mangle]
pub unsafe extern "C" fn options_array_assign(
    mut o: *mut options_entry,
    mut s: *const i8,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut separator: *const i8 = std::ptr::null::<i8>();
    let mut copy: *mut i8 = std::ptr::null_mut::<i8>();
    let mut next: *mut i8 = std::ptr::null_mut::<i8>();
    let mut string: *mut i8 = std::ptr::null_mut::<i8>();
    let mut i: u_int = 0;
    separator = (*(*o).tableentry).separator;
    if separator.is_null() {
        separator = b" ,\0" as *const u8 as *const i8;
    }
    if *separator as i32 == '\0' as i32 {
        if *s as i32 == '\0' as i32 {
            return 0 as i32;
        }
        i = 0 as i32 as u_int;
        while i
            < (2147483647 as i32 as u32)
                .wrapping_mul(2 as u32)
                .wrapping_add(1 as u32)
        {
            if (options_array_item(o, i)).is_null() {
                break;
            }
            i = i.wrapping_add(1);
        }
        return options_array_set(o, i, s, 0 as i32, cause);
    }
    if *s as i32 == '\0' as i32 {
        return 0 as i32;
    }
    string = xstrdup(s);
    copy = string;
    loop {
        next = strsep(&mut string, separator);
        if next.is_null() {
            break;
        }
        if *next as i32 == '\0' as i32 {
            continue;
        }
        i = 0 as i32 as u_int;
        while i
            < (2147483647 as i32 as u32)
                .wrapping_mul(2 as u32)
                .wrapping_add(1 as u32)
        {
            if (options_array_item(o, i)).is_null() {
                break;
            }
            i = i.wrapping_add(1);
        }
        if i == (2147483647 as i32 as u32)
            .wrapping_mul(2 as u32)
            .wrapping_add(1 as u32)
        {
            break;
        }
        if options_array_set(o, i, next, 0 as i32, cause) != 0 as i32 {
            free(copy as *mut libc::c_void);
            return -(1 as i32);
        }
    }
    free(copy as *mut libc::c_void);
    return 0 as i32;
}
#[no_mangle]
pub unsafe extern "C" fn options_array_first(mut o: *mut options_entry) -> *mut options_array_item {
    if ((*o).tableentry).is_null() || (*(*o).tableentry).flags & 0x1 as i32 == 0 {
        return std::ptr::null_mut::<options_array_item>();
    }
    return options_array_RB_MINMAX(&mut (*o).value.array, -(1 as i32));
}
#[no_mangle]
pub unsafe extern "C" fn options_array_next(
    mut a: *mut options_array_item,
) -> *mut options_array_item {
    return options_array_RB_NEXT(a);
}
#[no_mangle]
pub unsafe extern "C" fn options_array_item_index(mut a: *mut options_array_item) -> u_int {
    return (*a).index;
}
#[no_mangle]
pub unsafe extern "C" fn options_array_item_value(
    mut a: *mut options_array_item,
) -> *mut options_value {
    return &mut (*a).value;
}
#[no_mangle]
pub unsafe extern "C" fn options_is_array(mut o: *mut options_entry) -> i32 {
    return (!((*o).tableentry).is_null() && (*(*o).tableentry).flags & 0x1 as i32 != 0)
        as i32;
}
#[no_mangle]
pub unsafe extern "C" fn options_is_string(mut o: *mut options_entry) -> i32 {
    return (((*o).tableentry).is_null()
        || (*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_STRING as i32 as u32) as i32;
}
#[no_mangle]
pub unsafe extern "C" fn options_to_string(
    mut o: *mut options_entry,
    mut idx: i32,
    mut numeric: i32,
) -> *mut i8 {
    let mut a: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    let mut result: *mut i8 = std::ptr::null_mut::<i8>();
    let mut last: *mut i8 = std::ptr::null_mut::<i8>();
    let mut next: *mut i8 = std::ptr::null_mut::<i8>();
    if !((*o).tableentry).is_null() && (*(*o).tableentry).flags & 0x1 as i32 != 0 {
        if idx == -(1 as i32) {
            a = options_array_RB_MINMAX(&mut (*o).value.array, -(1 as i32));
            while !a.is_null() {
                next = options_value_to_string(o, &mut (*a).value, numeric);
                if last.is_null() {
                    result = next;
                } else {
                    xasprintf(
                        &mut result as *mut *mut i8,
                        b"%s %s\0" as *const u8 as *const i8,
                        last,
                        next,
                    );
                    free(last as *mut libc::c_void);
                    free(next as *mut libc::c_void);
                }
                last = result;
                a = options_array_RB_NEXT(a);
            }
            if result.is_null() {
                return xstrdup(b"\0" as *const u8 as *const i8);
            }
            return result;
        }
        a = options_array_item(o, idx as u_int);
        if a.is_null() {
            return xstrdup(b"\0" as *const u8 as *const i8);
        }
        return options_value_to_string(o, &mut (*a).value, numeric);
    }
    return options_value_to_string(o, &mut (*o).value, numeric);
}
#[no_mangle]
pub unsafe extern "C" fn options_parse(
    mut name: *const i8,
    mut idx: *mut i32,
) -> *mut i8 {
    let mut copy: *mut i8 = std::ptr::null_mut::<i8>();
    let mut cp: *mut i8 = std::ptr::null_mut::<i8>();
    let mut end: *mut i8 = std::ptr::null_mut::<i8>();
    if *name as i32 == '\0' as i32 {
        return std::ptr::null_mut::<i8>();
    }
    copy = xstrdup(name);
    cp = strchr(copy, '[' as i32);
    if cp.is_null() {
        *idx = -(1 as i32);
        return copy;
    }
    end = strchr(cp.offset(1 as i32 as isize), ']' as i32);
    if end.is_null()
        || *end.offset(1 as i32 as isize) as i32 != '\0' as i32
        || *(*__ctype_b_loc())
            .offset(*end.offset(-(1 as i32) as isize) as u_char as i32 as isize)
            as i32
            & _ISdigit as i32 as u16 as i32
            == 0
    {
        free(copy as *mut libc::c_void);
        return std::ptr::null_mut::<i8>();
    }
    if sscanf(cp, b"[%d]\0" as *const u8 as *const i8, idx) != 1 as i32
        || *idx < 0 as i32
    {
        free(copy as *mut libc::c_void);
        return std::ptr::null_mut::<i8>();
    }
    *cp = '\0' as i32 as i8;
    return copy;
}
#[no_mangle]
pub unsafe extern "C" fn options_parse_get(
    mut oo: *mut options,
    mut s: *const i8,
    mut idx: *mut i32,
    mut only: i32,
) -> *mut options_entry {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut name: *mut i8 = std::ptr::null_mut::<i8>();
    name = options_parse(s, idx);
    if name.is_null() {
        return std::ptr::null_mut::<options_entry>();
    }
    if only != 0 {
        o = options_get_only(oo, name);
    } else {
        o = options_get(oo, name);
    }
    free(name as *mut libc::c_void);
    return o;
}
#[no_mangle]
pub unsafe extern "C" fn options_match(
    mut s: *const i8,
    mut idx: *mut i32,
    mut ambiguous: *mut i32,
) -> *mut i8 {
    let mut oe: *const options_table_entry = std::ptr::null::<options_table_entry>();
    let mut found: *const options_table_entry = std::ptr::null::<options_table_entry>();
    let mut parsed: *mut i8 = std::ptr::null_mut::<i8>();
    let mut name: *const i8 = std::ptr::null::<i8>();
    let mut namelen: size_t = 0;
    parsed = options_parse(s, idx);
    if parsed.is_null() {
        return std::ptr::null_mut::<i8>();
    }
    if *parsed as i32 == '@' as i32 {
        *ambiguous = 0 as i32;
        return parsed;
    }
    name = options_map_name(parsed);
    namelen = strlen(name);
    found = std::ptr::null::<options_table_entry>();
    oe = options_table.as_ptr();
    while !((*oe).name).is_null() {
        if strcmp((*oe).name, name) == 0 as i32 {
            found = oe;
            break;
        } else {
            if strncmp((*oe).name, name, namelen) == 0 as i32 {
                if !found.is_null() {
                    *ambiguous = 1 as i32;
                    free(parsed as *mut libc::c_void);
                    return std::ptr::null_mut::<i8>();
                }
                found = oe;
            }
            oe = oe.offset(1);
        }
    }
    free(parsed as *mut libc::c_void);
    if found.is_null() {
        *ambiguous = 0 as i32;
        return std::ptr::null_mut::<i8>();
    }
    return xstrdup((*found).name);
}
#[no_mangle]
pub unsafe extern "C" fn options_match_get(
    mut oo: *mut options,
    mut s: *const i8,
    mut idx: *mut i32,
    mut only: i32,
    mut ambiguous: *mut i32,
) -> *mut options_entry {
    let mut name: *mut i8 = std::ptr::null_mut::<i8>();
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    name = options_match(s, idx, ambiguous);
    if name.is_null() {
        return std::ptr::null_mut::<options_entry>();
    }
    *ambiguous = 0 as i32;
    if only != 0 {
        o = options_get_only(oo, name);
    } else {
        o = options_get(oo, name);
    }
    free(name as *mut libc::c_void);
    return o;
}
#[no_mangle]
pub unsafe extern "C" fn options_get_string(
    mut oo: *mut options,
    mut name: *const i8,
) -> *const i8 {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    o = options_get(oo, name);
    if o.is_null() {
        fatalx(
            b"missing option %s\0" as *const u8 as *const i8,
            name,
        );
    }
    if !(((*o).tableentry).is_null()
        || (*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_STRING as i32 as u32)
    {
        fatalx(
            b"option %s is not a string\0" as *const u8 as *const i8,
            name,
        );
    }
    return (*o).value.string;
}
#[no_mangle]
pub unsafe extern "C" fn options_get_number(
    mut oo: *mut options,
    mut name: *const i8,
) -> i64 {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    o = options_get(oo, name);
    if o.is_null() {
        fatalx(
            b"missing option %s\0" as *const u8 as *const i8,
            name,
        );
    }
    if !(!((*o).tableentry).is_null()
        && ((*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_NUMBER as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_KEY as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_COLOUR as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_FLAG as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_CHOICE as i32 as u32))
    {
        fatalx(
            b"option %s is not a number\0" as *const u8 as *const i8,
            name,
        );
    }
    return (*o).value.number;
}
#[no_mangle]
pub unsafe extern "C" fn options_set_string(
    mut oo: *mut options,
    mut name: *const i8,
    mut append: i32,
    mut fmt: *const i8,
    mut args: ...
) -> *mut options_entry {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut ap: ::core::ffi::VaListImpl;
    let mut separator: *const i8 = b"\0" as *const u8 as *const i8;
    let mut s: *mut i8 = std::ptr::null_mut::<i8>();
    let mut value: *mut i8 = std::ptr::null_mut::<i8>();
    ap = args.clone();
    xvasprintf(&mut s, fmt, ap.as_va_list());
    o = options_get_only(oo, name);
    if !o.is_null()
        && append != 0
        && (((*o).tableentry).is_null()
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_STRING as i32 as u32)
    {
        if *name as i32 != '@' as i32 {
            separator = (*(*o).tableentry).separator;
            if separator.is_null() {
                separator = b"\0" as *const u8 as *const i8;
            }
        }
        xasprintf(
            &mut value as *mut *mut i8,
            b"%s%s%s\0" as *const u8 as *const i8,
            (*o).value.string,
            separator,
            s,
        );
        free(s as *mut libc::c_void);
    } else {
        value = s;
    }
    if o.is_null() && *name as i32 == '@' as i32 {
        o = options_add(oo, name);
    } else if o.is_null() {
        o = options_default(oo, options_parent_table_entry(oo, name));
        if o.is_null() {
            return std::ptr::null_mut::<options_entry>();
        }
    }
    if !(((*o).tableentry).is_null()
        || (*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_STRING as i32 as u32)
    {
        fatalx(
            b"option %s is not a string\0" as *const u8 as *const i8,
            name,
        );
    }
    free((*o).value.string as *mut libc::c_void);
    (*o).value.string = value;
    (*o).cached = 0 as i32;
    return o;
}
#[no_mangle]
pub unsafe extern "C" fn options_set_number(
    mut oo: *mut options,
    mut name: *const i8,
    mut value: i64,
) -> *mut options_entry {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    if *name as i32 == '@' as i32 {
        fatalx(
            b"user option %s must be a string\0" as *const u8 as *const i8,
            name,
        );
    }
    o = options_get_only(oo, name);
    if o.is_null() {
        o = options_default(oo, options_parent_table_entry(oo, name));
        if o.is_null() {
            return std::ptr::null_mut::<options_entry>();
        }
    }
    if !(!((*o).tableentry).is_null()
        && ((*(*o).tableentry).type_0 as u32
            == OPTIONS_TABLE_NUMBER as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_KEY as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_COLOUR as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_FLAG as i32 as u32
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_CHOICE as i32 as u32))
    {
        fatalx(
            b"option %s is not a number\0" as *const u8 as *const i8,
            name,
        );
    }
    (*o).value.number = value;
    return o;
}
#[no_mangle]
pub unsafe extern "C" fn options_scope_from_name(
    mut args: *mut args,
    mut window: i32,
    mut name: *const i8,
    mut fs: *mut cmd_find_state,
    mut oo: *mut *mut options,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut s: *mut session = (*fs).s;
    let mut wl: *mut winlink = (*fs).wl;
    let mut wp: *mut window_pane = (*fs).wp;
    let mut target: *const i8 = args_get(args, 't' as i32 as u_char);
    let mut oe: *const options_table_entry = std::ptr::null::<options_table_entry>();
    let mut scope: i32 = 0 as i32;
    if *name as i32 == '@' as i32 {
        return options_scope_from_flags(args, window, fs, oo, cause);
    }
    oe = options_table.as_ptr();
    while !((*oe).name).is_null() {
        if strcmp((*oe).name, name) == 0 as i32 {
            break;
        }
        oe = oe.offset(1);
    }
    if ((*oe).name).is_null() {
        xasprintf(
            cause,
            b"unknown option: %s\0" as *const u8 as *const i8,
            name,
        );
        return 0 as i32;
    }
    let mut current_block_38: u64;
    match (*oe).scope {
        1 => {
            *oo = global_options;
            scope = 0x1 as i32;
            current_block_38 = 980989089337379490;
        }
        2 => {
            if args_has(args, 'g' as i32 as u_char) != 0 {
                *oo = global_s_options;
                scope = 0x2 as i32;
            } else if s.is_null() && !target.is_null() {
                xasprintf(
                    cause,
                    b"no such session: %s\0" as *const u8 as *const i8,
                    target,
                );
            } else if s.is_null() {
                xasprintf(
                    cause,
                    b"no current session\0" as *const u8 as *const i8,
                );
            } else {
                *oo = (*s).options;
                scope = 0x2 as i32;
            }
            current_block_38 = 980989089337379490;
        }
        12 => {
            if args_has(args, 'p' as i32 as u_char) != 0 {
                if wp.is_null() && !target.is_null() {
                    xasprintf(
                        cause,
                        b"no such pane: %s\0" as *const u8 as *const i8,
                        target,
                    );
                } else if wp.is_null() {
                    xasprintf(
                        cause,
                        b"no current pane\0" as *const u8 as *const i8,
                    );
                } else {
                    *oo = (*wp).options;
                    scope = 0x8 as i32;
                }
                current_block_38 = 980989089337379490;
            } else {
                current_block_38 = 11068587321415786614;
            }
        }
        4 => {
            current_block_38 = 11068587321415786614;
        }
        _ => {
            current_block_38 = 980989089337379490;
        }
    }
    match current_block_38 {
        11068587321415786614 => {
            if args_has(args, 'g' as i32 as u_char) != 0 {
                *oo = global_w_options;
                scope = 0x4 as i32;
            } else if wl.is_null() && !target.is_null() {
                xasprintf(
                    cause,
                    b"no such window: %s\0" as *const u8 as *const i8,
                    target,
                );
            } else if wl.is_null() {
                xasprintf(
                    cause,
                    b"no current window\0" as *const u8 as *const i8,
                );
            } else {
                *oo = (*(*wl).window).options;
                scope = 0x4 as i32;
            }
        }
        _ => {}
    }
    return scope;
}
#[no_mangle]
pub unsafe extern "C" fn options_scope_from_flags(
    mut args: *mut args,
    mut window: i32,
    mut fs: *mut cmd_find_state,
    mut oo: *mut *mut options,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut s: *mut session = (*fs).s;
    let mut wl: *mut winlink = (*fs).wl;
    let mut wp: *mut window_pane = (*fs).wp;
    let mut target: *const i8 = args_get(args, 't' as i32 as u_char);
    if args_has(args, 's' as i32 as u_char) != 0 {
        *oo = global_options;
        return 0x1 as i32;
    }
    if args_has(args, 'p' as i32 as u_char) != 0 {
        if wp.is_null() {
            if !target.is_null() {
                xasprintf(
                    cause,
                    b"no such pane: %s\0" as *const u8 as *const i8,
                    target,
                );
            } else {
                xasprintf(
                    cause,
                    b"no current pane\0" as *const u8 as *const i8,
                );
            }
            return 0 as i32;
        }
        *oo = (*wp).options;
        return 0x8 as i32;
    } else if window != 0 || args_has(args, 'w' as i32 as u_char) != 0 {
        if args_has(args, 'g' as i32 as u_char) != 0 {
            *oo = global_w_options;
            return 0x4 as i32;
        }
        if wl.is_null() {
            if !target.is_null() {
                xasprintf(
                    cause,
                    b"no such window: %s\0" as *const u8 as *const i8,
                    target,
                );
            } else {
                xasprintf(
                    cause,
                    b"no current window\0" as *const u8 as *const i8,
                );
            }
            return 0 as i32;
        }
        *oo = (*(*wl).window).options;
        return 0x4 as i32;
    } else {
        if args_has(args, 'g' as i32 as u_char) != 0 {
            *oo = global_s_options;
            return 0x2 as i32;
        }
        if s.is_null() {
            if !target.is_null() {
                xasprintf(
                    cause,
                    b"no such session: %s\0" as *const u8 as *const i8,
                    target,
                );
            } else {
                xasprintf(
                    cause,
                    b"no current session\0" as *const u8 as *const i8,
                );
            }
            return 0 as i32;
        }
        *oo = (*s).options;
        return 0x2 as i32;
    };
}
#[no_mangle]
pub unsafe extern "C" fn options_string_to_style(
    mut oo: *mut options,
    mut name: *const i8,
    mut ft: *mut format_tree,
) -> *mut style {
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut s: *const i8 = std::ptr::null::<i8>();
    let mut expanded: *mut i8 = std::ptr::null_mut::<i8>();
    o = options_get(oo, name);
    if o.is_null()
        || !(((*o).tableentry).is_null()
            || (*(*o).tableentry).type_0 as u32
                == OPTIONS_TABLE_STRING as i32 as u32)
    {
        return std::ptr::null_mut::<style>();
    }
    if (*o).cached != 0 {
        return &mut (*o).style;
    }
    s = (*o).value.string;
    log_debug(
        b"%s: %s is '%s'\0" as *const u8 as *const i8,
        (*::core::mem::transmute::<&[u8; 24], &[i8; 24]>(b"options_string_to_style\0"))
            .as_ptr(),
        name,
        s,
    );
    style_set(&mut (*o).style, &grid_default_cell);
    (*o).cached = (strstr(s, b"#{\0" as *const u8 as *const i8)
        == std::ptr::null_mut::<libc::c_void>() as *mut i8)
        as i32;
    if !ft.is_null() && (*o).cached == 0 {
        expanded = format_expand(ft, s);
        if style_parse(&mut (*o).style, &grid_default_cell, expanded) != 0 as i32 {
            free(expanded as *mut libc::c_void);
            return std::ptr::null_mut::<style>();
        }
        free(expanded as *mut libc::c_void);
    } else if style_parse(&mut (*o).style, &grid_default_cell, s) != 0 as i32 {
        return std::ptr::null_mut::<style>();
    }
    return &mut (*o).style;
}
unsafe extern "C" fn options_from_string_check(
    mut oe: *const options_table_entry,
    mut value: *const i8,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut sy: style = style {
        gc: grid_cell {
            data: utf8_data {
                data: [0; 21],
                have: 0,
                size: 0,
                width: 0,
            },
            attr: 0,
            flags: 0,
            fg: 0,
            bg: 0,
            us: 0,
            link: 0,
        },
        ignore: 0,
        fill: 0,
        align: STYLE_ALIGN_DEFAULT,
        list: STYLE_LIST_OFF,
        range_type: STYLE_RANGE_NONE,
        range_argument: 0,
        range_string: [0; 16],
        width: 0,
        pad: 0,
        default_type: STYLE_DEFAULT_BASE,
    };
    if oe.is_null() {
        return 0 as i32;
    }
    if strcmp(
        (*oe).name,
        b"default-shell\0" as *const u8 as *const i8,
    ) == 0 as i32
        && checkshell(value) == 0
    {
        xasprintf(
            cause,
            b"not a suitable shell: %s\0" as *const u8 as *const i8,
            value,
        );
        return -(1 as i32);
    }
    if !((*oe).pattern).is_null()
        && fnmatch((*oe).pattern, value, 0 as i32) != 0 as i32
    {
        xasprintf(
            cause,
            b"value is invalid: %s\0" as *const u8 as *const i8,
            value,
        );
        return -(1 as i32);
    }
    if (*oe).flags & 0x4 as i32 != 0
        && (strstr(value, b"#{\0" as *const u8 as *const i8)).is_null()
        && style_parse(&mut sy, &grid_default_cell, value) != 0 as i32
    {
        xasprintf(
            cause,
            b"invalid style: %s\0" as *const u8 as *const i8,
            value,
        );
        return -(1 as i32);
    }
    return 0 as i32;
}
unsafe extern "C" fn options_from_string_flag(
    mut oo: *mut options,
    mut name: *const i8,
    mut value: *const i8,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut flag: i32 = 0;
    if value.is_null() || *value as i32 == '\0' as i32 {
        flag = (options_get_number(oo, name) == 0) as i32;
    } else if strcmp(value, b"1\0" as *const u8 as *const i8) == 0 as i32
        || strcasecmp(value, b"on\0" as *const u8 as *const i8) == 0 as i32
        || strcasecmp(value, b"yes\0" as *const u8 as *const i8) == 0 as i32
    {
        flag = 1 as i32;
    } else if strcmp(value, b"0\0" as *const u8 as *const i8) == 0 as i32
        || strcasecmp(value, b"off\0" as *const u8 as *const i8) == 0 as i32
        || strcasecmp(value, b"no\0" as *const u8 as *const i8) == 0 as i32
    {
        flag = 0 as i32;
    } else {
        xasprintf(
            cause,
            b"bad value: %s\0" as *const u8 as *const i8,
            value,
        );
        return -(1 as i32);
    }
    options_set_number(oo, name, flag as i64);
    return 0 as i32;
}
#[no_mangle]
pub unsafe extern "C" fn options_find_choice(
    mut oe: *const options_table_entry,
    mut value: *const i8,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut cp: *mut *const i8 = std::ptr::null_mut::<*const i8>();
    let mut n: i32 = 0 as i32;
    let mut choice: i32 = -(1 as i32);
    cp = (*oe).choices;
    while !(*cp).is_null() {
        if strcmp(*cp, value) == 0 as i32 {
            choice = n;
        }
        n += 1;
        cp = cp.offset(1);
    }
    if choice == -(1 as i32) {
        xasprintf(
            cause,
            b"unknown value: %s\0" as *const u8 as *const i8,
            value,
        );
        return -(1 as i32);
    }
    return choice;
}
unsafe extern "C" fn options_from_string_choice(
    mut oe: *const options_table_entry,
    mut oo: *mut options,
    mut name: *const i8,
    mut value: *const i8,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut choice: i32 = -(1 as i32);
    if value.is_null() {
        choice = options_get_number(oo, name) as i32;
        if choice < 2 as i32 {
            choice = (choice == 0) as i32;
        }
    } else {
        choice = options_find_choice(oe, value, cause);
        if choice < 0 as i32 {
            return -(1 as i32);
        }
    }
    options_set_number(oo, name, choice as i64);
    return 0 as i32;
}
#[no_mangle]
pub unsafe extern "C" fn options_from_string(
    mut oo: *mut options,
    mut oe: *const options_table_entry,
    mut name: *const i8,
    mut value: *const i8,
    mut append: i32,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut type_0: options_table_type = OPTIONS_TABLE_STRING;
    let mut number: i64 = 0;
    let mut errstr: *const i8 = std::ptr::null::<i8>();
    let mut new: *const i8 = std::ptr::null::<i8>();
    let mut old: *mut i8 = std::ptr::null_mut::<i8>();
    let mut key: key_code = 0;
    if !oe.is_null() {
        if value.is_null()
            && (*oe).type_0 as u32 != OPTIONS_TABLE_FLAG as i32 as u32
            && (*oe).type_0 as u32 != OPTIONS_TABLE_CHOICE as i32 as u32
        {
            xasprintf(cause, b"empty value\0" as *const u8 as *const i8);
            return -(1 as i32);
        }
        type_0 = (*oe).type_0;
    } else {
        if *name as i32 != '@' as i32 {
            xasprintf(
                cause,
                b"bad option name\0" as *const u8 as *const i8,
            );
            return -(1 as i32);
        }
        type_0 = OPTIONS_TABLE_STRING;
    }
    match type_0 as u32 {
        0 => {
            old = xstrdup(options_get_string(oo, name));
            options_set_string(
                oo,
                name,
                append,
                b"%s\0" as *const u8 as *const i8,
                value,
            );
            new = options_get_string(oo, name);
            if options_from_string_check(oe, new, cause) != 0 as i32 {
                options_set_string(
                    oo,
                    name,
                    0 as i32,
                    b"%s\0" as *const u8 as *const i8,
                    old,
                );
                free(old as *mut libc::c_void);
                return -(1 as i32);
            }
            free(old as *mut libc::c_void);
            return 0 as i32;
        }
        1 => {
            number = strtonum(
                value,
                (*oe).minimum as i64,
                (*oe).maximum as i64,
                &mut errstr,
            );
            if !errstr.is_null() {
                xasprintf(
                    cause,
                    b"value is %s: %s\0" as *const u8 as *const i8,
                    errstr,
                    value,
                );
                return -(1 as i32);
            }
            options_set_number(oo, name, number);
            return 0 as i32;
        }
        2 => {
            key = key_string_lookup_string(value);
            if key == 0xfe000000000 as u64 {
                xasprintf(
                    cause,
                    b"bad key: %s\0" as *const u8 as *const i8,
                    value,
                );
                return -(1 as i32);
            }
            options_set_number(oo, name, key as i64);
            return 0 as i32;
        }
        3 => {
            number = colour_fromstring(value) as i64;
            if number == -(1 as i32) as i64 {
                xasprintf(
                    cause,
                    b"bad colour: %s\0" as *const u8 as *const i8,
                    value,
                );
                return -(1 as i32);
            }
            options_set_number(oo, name, number);
            return 0 as i32;
        }
        4 => return options_from_string_flag(oo, name, value, cause),
        5 => return options_from_string_choice(oe, oo, name, value, cause),
        6 | _ => {}
    }
    return -(1 as i32);
}
#[no_mangle]
pub unsafe extern "C" fn options_push_changes(mut name: *const i8) {
    let mut loop_0: *mut client = std::ptr::null_mut::<client>();
    let mut s: *mut session = std::ptr::null_mut::<session>();
    let mut w: *mut window = std::ptr::null_mut::<window>();
    let mut wp: *mut window_pane = std::ptr::null_mut::<window_pane>();
    log_debug(
        b"%s: %s\0" as *const u8 as *const i8,
        (*::core::mem::transmute::<&[u8; 21], &[i8; 21]>(b"options_push_changes\0"))
            .as_ptr(),
        name,
    );
    if strcmp(
        name,
        b"automatic-rename\0" as *const u8 as *const i8,
    ) == 0 as i32
    {
        w = windows_RB_MINMAX(&mut windows, -(1 as i32));
        while !w.is_null() {
            if !((*w).active).is_null() {
                if options_get_number((*w).options, name) != 0 {
                    (*(*w).active).flags |= 0x80 as i32;
                }
            }
            w = windows_RB_NEXT(w);
        }
    }
    if strcmp(name, b"cursor-colour\0" as *const u8 as *const i8) == 0 as i32 {
        wp = window_pane_tree_RB_MINMAX(&mut all_window_panes, -(1 as i32));
        while !wp.is_null() {
            window_pane_default_cursor(wp);
            wp = window_pane_tree_RB_NEXT(wp);
        }
    }
    if strcmp(name, b"cursor-style\0" as *const u8 as *const i8) == 0 as i32 {
        wp = window_pane_tree_RB_MINMAX(&mut all_window_panes, -(1 as i32));
        while !wp.is_null() {
            window_pane_default_cursor(wp);
            wp = window_pane_tree_RB_NEXT(wp);
        }
    }
    if strcmp(
        name,
        b"fill-character\0" as *const u8 as *const i8,
    ) == 0 as i32
    {
        w = windows_RB_MINMAX(&mut windows, -(1 as i32));
        while !w.is_null() {
            window_set_fill_character(w);
            w = windows_RB_NEXT(w);
        }
    }
    if strcmp(name, b"key-table\0" as *const u8 as *const i8) == 0 as i32 {
        loop_0 = clients.tqh_first;
        while !loop_0.is_null() {
            server_client_set_key_table(loop_0, std::ptr::null::<i8>());
            loop_0 = (*loop_0).entry.tqe_next;
        }
    }
    if strcmp(name, b"user-keys\0" as *const u8 as *const i8) == 0 as i32 {
        loop_0 = clients.tqh_first;
        while !loop_0.is_null() {
            if (*loop_0).tty.flags & 0x20 as i32 != 0 {
                tty_keys_build(&mut (*loop_0).tty);
            }
            loop_0 = (*loop_0).entry.tqe_next;
        }
    }
    if strcmp(name, b"status\0" as *const u8 as *const i8) == 0 as i32
        || strcmp(
            name,
            b"status-interval\0" as *const u8 as *const i8,
        ) == 0 as i32
    {
        status_timer_start_all();
    }
    if strcmp(
        name,
        b"monitor-silence\0" as *const u8 as *const i8,
    ) == 0 as i32
    {
        alerts_reset_all();
    }
    if strcmp(name, b"window-style\0" as *const u8 as *const i8) == 0 as i32
        || strcmp(
            name,
            b"window-active-style\0" as *const u8 as *const i8,
        ) == 0 as i32
    {
        wp = window_pane_tree_RB_MINMAX(&mut all_window_panes, -(1 as i32));
        while !wp.is_null() {
            (*wp).flags |= 0x1000 as i32;
            wp = window_pane_tree_RB_NEXT(wp);
        }
    }
    if strcmp(name, b"pane-colours\0" as *const u8 as *const i8) == 0 as i32 {
        wp = window_pane_tree_RB_MINMAX(&mut all_window_panes, -(1 as i32));
        while !wp.is_null() {
            colour_palette_from_option(&mut (*wp).palette, (*wp).options);
            wp = window_pane_tree_RB_NEXT(wp);
        }
    }
    if strcmp(
        name,
        b"pane-border-status\0" as *const u8 as *const i8,
    ) == 0 as i32
        || strcmp(
            name,
            b"pane-scrollbars\0" as *const u8 as *const i8,
        ) == 0 as i32
        || strcmp(
            name,
            b"pane-scrollbars-position\0" as *const u8 as *const i8,
        ) == 0 as i32
    {
        w = windows_RB_MINMAX(&mut windows, -(1 as i32));
        while !w.is_null() {
            layout_fix_panes(w, std::ptr::null_mut::<window_pane>());
            w = windows_RB_NEXT(w);
        }
    }
    if strcmp(
        name,
        b"pane-scrollbars-style\0" as *const u8 as *const i8,
    ) == 0 as i32
    {
        wp = window_pane_tree_RB_MINMAX(&mut all_window_panes, -(1 as i32));
        while !wp.is_null() {
            style_set_scrollbar_style_from_option(&mut (*wp).scrollbar_style, (*wp).options);
            wp = window_pane_tree_RB_NEXT(wp);
        }
        w = windows_RB_MINMAX(&mut windows, -(1 as i32));
        while !w.is_null() {
            layout_fix_panes(w, std::ptr::null_mut::<window_pane>());
            w = windows_RB_NEXT(w);
        }
    }
    if strcmp(
        name,
        b"input-buffer-size\0" as *const u8 as *const i8,
    ) == 0 as i32
    {
        input_set_buffer_size(options_get_number(global_options, name) as size_t);
    }
    s = sessions_RB_MINMAX(&mut sessions, -(1 as i32));
    while !s.is_null() {
        status_update_cache(s);
        s = sessions_RB_NEXT(s);
    }
    recalculate_sizes();
    loop_0 = clients.tqh_first;
    while !loop_0.is_null() {
        if !((*loop_0).session).is_null() {
            server_redraw_client(loop_0);
        }
        loop_0 = (*loop_0).entry.tqe_next;
    }
}
#[no_mangle]
pub unsafe extern "C" fn options_remove_or_default(
    mut o: *mut options_entry,
    mut idx: i32,
    mut cause: *mut *mut i8,
) -> i32 {
    let mut oo: *mut options = (*o).owner;
    if idx == -(1 as i32) {
        if !((*o).tableentry).is_null()
            && (oo == global_options || oo == global_s_options || oo == global_w_options)
        {
            options_default(oo, (*o).tableentry);
        } else {
            options_remove(o);
        }
    } else if options_array_set(
        o,
        idx as u_int,
        std::ptr::null::<i8>(),
        0 as i32,
        cause,
    ) != 0 as i32
    {
        return -(1 as i32);
    }
    return 0 as i32;
}
